Why does the hint work?


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

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

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


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