Iterating Over Hashes - write way / wrong way?


#1

sorry I'm a super noob but I was wondering

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

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

and

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

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

both seem to work
is one better ? is one wrong ?


#2

@betaace33323

are both the same thing. You can see, the first one uses curly brackets while the second one uses do-end keyword.


#3

The first one is usually used when your block only consists of one line. The second one is usually used if the block has more lines.