Ruby Build an Address Book in Ruby Input and Output Searching the Address Book

Searching the Address Book - Task 2

I didn't get the question clear to pass this challenge, here's solution.

Challenge Task 2 of 2

In the search method, call the find_by_name, find_by_address, and find_by_phone_number methods with the argument passed >in to the search method. You can assume that these methods are already defined and do not have to write them.

class AddressBook
  def search(contact)
  end

 #methods are already defined and do not have to write them.

end

address_book = AddressBook.new
address_book.find_by_name(contact)
address_book.find_by_address(contact)
address_book.find_by_phone_number(contact)

Any idea? :/

1 Answer

Tim Knight
Tim Knight
28,861 Points

Salman,

Read through the question again:

In the search method, call the find_by_name, find_by_address, and find_by_phone_number methods with the argument passed in to the search method. You can assume that these methods are already defined and do not have to write them.

It's asking you to add the calls to those methods within the search method, so your answer would look something like this:

class AddressBook
  def search(contact)
    find_by_name(contact)
    find_by_address(contact)
    find_by_phone_number(contact)
  end
end

address_book = AddressBook.new

Ah d-oh! I was confused with calling to those method with argument outside class, tried to figure out the solution. Got it now!

Thanks Tim