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

Michael Cook
Michael Cook
3,425 Points

Hi! I'm not exactly sure what to do in Ruby Loops section 4, where I have to assign hash values from methods. Thanks!

Just as the title says! I tried some code here and there, but with this one, it just really hits me hard. I don't have much clue on what to do. The code below is the starting code the challenge gives you.

contact.rb
contact_list = []

contact = {"name" => "", "phone_number" => "" }

5 Answers

Antonio De Rose
Antonio De Rose
19,452 Points

question says, that assume that the function for get_name is already there with no parameters, and asks you to call the get_name function, and the return value, should update the hash name in the contact array

contact_list = []

contact = {"name" => "", "phone_number" => "" }

#I have written the function for you, which you do not have to write, 
#just to give you an understanding on what the broader level of question
#in the challenge you should not write this below function, instead how you
#call that function to update the name hash in contact array
def get_name()
  print "what is your name ? "
  return gets.chomp
end
Michael Cook
Michael Cook
3,425 Points

Thanks, that helped a little, but I'm not sure how to exactly have get_name edit the hash at all.

Michael Cook
Michael Cook
3,425 Points

Looking at the videos and watching them again, I'm not sure how to get get_name to edit the hash without editing get_name itself, sorry if I'm missing something important.

Michael Cook
Michael Cook
3,425 Points

Alright, well I figured it out on my own, but thanks for your help! I appreciate it!

Alexander Fritsch
Alexander Fritsch
3,184 Points

Dude...

Others have befallen your turmoil.

What was the fix?

Alexander Fritsch
Alexander Fritsch
3,184 Points

Ok I too figured it out...

Don't listen to Antonio De Rose's answer as it implies you must pass a string to the get_name method.

The answer is you're overthinking it... Just call the method IN the hash.