Ruby Ruby Loops Build a Simple Contact List Assigning Hash Values From Methods

Steven Saliba
Steven Saliba
2,667 Points

I need some help. I believe my code is close to passing.

This contact.rb file is part of a larger program. Elsewhere in the program, we've defined a get_name method that takes no arguments, and returns a string.

The code currently in contact.rb creates a contact hash with a "name" key that has an empty string as its value. Update the code to call the get_name method, and assign the return value of get_name to the "name" key in the contact hash.

contact.rb
def get_name
contact_list = []
contact = {"name" => get_name(), "phone_number" => "" }
get_name=["name"]
  return contact
end

2 Answers

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 56,072 Points

Hi Steven,

You don't want to define a method called get_name - that's already done according to the question.

This method returns a string, and we want to use that returned value to store against the "name" key in the hash. So, replace the existing "" with a call to the get_name method, as you have done. That's it; just delete the two double-quotes and add a call to the method. Remove your def and the other additional lines of code - those aren't required.

Steve.

Steven Saliba
Steven Saliba
2,667 Points

Thank you Steve, I will try that.