Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Build an Address Book in Ruby!
You have completed Build an Address Book in Ruby!
Preview
In our final bit of search functionality, we add the ability to search by address.
Code Samples
def find_by_address(query)
results = []
search = query.downcase
contacts.each do |contact|
contact.addresses.each do |address|
if address.to_s('long').downcase.include?(search)
results.push(contact) unless results.include?(contact)
end
end
end
print_results("Address search results (#{search})", results)
end
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Finally, let's go ahead and add the
ability to find somebody by their address.
0:00
Now, this is going to follow a similar
pattern as finding by name and
0:05
phone number, except this time we're
going to be querying by the address.
0:10
So, let's go ahead and
create a method to find by an address.
0:14
Now if we scroll up,
0:24
we can see we have this pattern of
creating an empty results array and
0:25
then manipulating the search to get sent
in, and then looping through the contacts,
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up