2. iterating over hashes can someone explain


#1

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] }

https://www.codecademy.com/en/courses/ruby-beginner-en-Qn7Qw/0/2?curriculum_id=5059f8619189a5000201fbcb


#3

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

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

is not working.. help anyone


#4

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


#5

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


#6

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

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

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.