So I have an id that gets attached to the contact with each entry to the
array. Now i want to be able to locate a specific entry using the id's
as the identifier. I am new to ruby so any help is appreciated, thanks.
So I have an id that gets attached to the contact with each entry to the
array. Now i want to be able to locate a specific entry using the id's
as the identifier. I am new to ruby so any help is appreciated, thanks.
The easiest way would be:
def self.find_contact(contact_id) @contacts.find{|c| c.id == contact_id }
end
The documentation for the `find' method is here
However that's a linear search over the array for each lookup. An
alternative might be something like this:
class List @contacts = {} # Hash, not array @id = 1000