"Build a Simple iPhone App with Swift 2.0" was retired on May 31, 2020. You are now viewing the recommended replacement.
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!
In this video, we implement a method to search for contacts by their name.
Code Samples
Here is our find_by_name method:
def find_by_name(name)
results = []
search = name.downcase
contacts.each do |contact|
if contact.full_name.downcase.include?(search)
results.push(contact)
end
end
puts "Name search results (#{search})"
results.each do |contact|
puts contact.to_s('full_name')
contact.print_phone_numbers
contact.print_addresses
puts "\n"
end
end
Which we can call as follows:
address_book.find_by_name("e")
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
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