Why does the hint work?


#1

matz = { "First name" => "Yukihiro",
"Last name" => "Matsumoto",
"Age" => 47,
"Nationality" => "Japanese",
"Nickname" => "Matz"
}

matz.each do |key,value|
puts matz[key]
end

puts matz[key] prints out the value. Why wouldn't it print the key instead?


#2

Hi @cmosley ,

The syntax, matz[key], uses key to access the value that is associated with it. If you want to print the key from within the loop, use ...

puts key