Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Jason Chow
Jason Chow
4,428 Points

contact list

contact_list = []

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

Assign the value of the key name to the return value of the method get_name() in the contact hash. Assume that get_name() returns a string

How do i write it?

My attempts :

                       1.     get_name() = contact["name"]
                       2.    get_name() = contact[""] 

Thanks guys!!

contact.rb
contact_list = []

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

get_name() = contact.each_value ["name"]

1 Answer

Brandon Hartman
Brandon Hartman
8,032 Points

All you have to write is get_name() where the "" are.

contact = {"name" => get_name(), "phone_number" => "" }

Hope this helps!