(puts value) vs (puts value, matz[value])


#1

After reading other comments it seems the majority come up with something like this:

option 1

matz = { "First name" => "Yukihiro",
"Last name" => "Matsumoto",
"Age" => 47,
"Nationality" => "Japanese",
"Nickname" => "Matz"
}
matz.each { |key, value|
puts value, matz[value]
}

option 2

matz = { "First name" => "Yukihiro",
"Last name" => "Matsumoto",
"Age" => 47,
"Nationality" => "Japanese",
"Nickname" => "Matz"
}
matz.each { |key, value|
puts value
}

Option 1 does put out the same result as Option 2, but it also adds a break between the results.

  1. My actual question is: What does the "puts value, matz[value]" part actually do?
  2. Follow up: Why have others used "matz[key]" instead of "matz[value]" since you are trying to put out the value and not the key?

#2

Displaying matz[value] doesn't make much sense to me. The hash matz has no keys which correspond to value (since value takes each value from the hash and not each key).

And if you try the option 1 in the lab, you'll see that there's nil being displayed where matz[value] should be, which is a logical result, but not necessary for the exercise (and doesn't really serve a purpose).