Ruby Ruby Loops Build a Simple Contact List Hash and Array Iteration

What does it mean... "Assign"

I don't know how to Assign array items to a variable.

contact_list.rb
contact_list = [
  {"name" => "Jason", "phone_number" => "123"},
  {"name" => "Nick", "phone_number" => "456"}
]
contact_list.each do |item|

1 Answer

Nathan Williams
STAFF
Nathan Williams
Treehouse Staff

Hi Zachary,

The variable on the "slide" (i.e. "|item|") is the named variable used to access the element within the block.

For example:

contacts = ['Bob', 'Jane', 'Sue']

contacts.each do |contact|
  puts contact
end

would return

Bob
Jane
Sue

An alternative syntax for this, which avoids the do...end syntax would be:

contacts = ['Bob', 'Jane', 'Sue']

contacts.each { |contact| puts contact }

Hope that helps!

I don't understand any of the challenge... I really just need the answer, so i can work back from it...

and why does it keep disconnecting while I'm doing the challenge, then have to restart?