2. iterating over hashes can someone explain


both these codes work but i don't really understand it can someone explain please?
matz.each { |key, value| puts value, matz[value] }

matz.each { |key, value| puts matz[key] }



Am trying it matz.each do |"First name", "Yukihiro"|

puts "First name" , matz ["First name"]

is not working.. help anyone


The |key| and |value| are variables, you can't put them in quotations.


the matz.each code chooses the key and value from the hash, while puts just tells it what to print out. the only difference between the codes you show is that one does not puts values in the console. good luck


After the code that's ontop, start a new line, or syntax. E.g.

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

We do not want to put "KEY" because that refers to the first values. So, instead we input "VALUE" because it refers to the second values that we want to print.