Data Structures Section 10


Question is this: In the snippet of code below: Does ruby automatically know that x is equal to the first stored value and y is the second? I may have missed this if it was covered in an earlier lesson, but I just want to be sure I understand how Ruby knows when running the below code to print the specific value that is being called.

Any and all help is greatly appreciated.

friends = ["Milhouse", "Ralph", "Nelson", "Otto"]

family = { "Homer" => "dad",
  "Marge" => "mom",
  "Lisa" => "sister",
  "Maggie" => "sister",
  "Abe" => "grandpa",
  "Santa's Little Helper" => "dog"

friends.each { |x| puts "#{x}" }
family.each { |x, y| puts "#{x}: #{y}" }

Yes, Ruby recognizes x as the key and y as the value of the hash automatically.