What's a neat way to print multiple Hash-es?


#1

So, it's not that I'm stuck at it, but I want to see if anyone have any input in how we can print an X amount of Hashes without having to type out each one individually. You'll see what I mean on the code I wrote below.

pets = {
"Joey" => "Human",
"Annie" => "Bear",
"Nidalee" => "Leopard"
}

puts pets["Joey"]
puts pets["Annie"]
puts pets["Nidalee"]


#2

@corejumper77999,

pets = {
 "Joey" => "Human",
 "Annie" => "Bear",
 "Nidalee" => "Leopard"
}
pets.each { | key,value |
  puts "#{key} #{value}"
}
#OR
pets.each_with_index { |(key,value),index| 
print "key: #{key}, value: #{value}, index: #{index}\n"
}