Added sorting to phone, both moving individual contacts and sorting all at once

This commit is contained in:
Maruno17
2022-09-10 23:20:40 +01:00
parent 25a8d727ab
commit 4fcd19e247
2 changed files with 94 additions and 13 deletions

View File

@@ -116,9 +116,23 @@ class Phone
@contacts.push(contact)
end
end
sort_contacts
return true
end
# Rearranges the list of phone contacts to put all visible contacts first,
# followed by all invisible contacts.
def sort_contacts
new_contacts = []
2.times do |i|
@contacts.each do |con|
next if (i == 0 && !con.visible?) || (i == 1 && con.visible?)
new_contacts.push(con)
end
end
@contacts = new_contacts
end
#=============================================================================
# Checks once every second.