I want to iterate through each value of each array of a hash. Normally, to select a value in an array, I would do this:
array = ["1", "2"]
array.each do |x| puts x end
But how do I iterate through the array if it is in a hash?
This is my code:
hash = {1 => {"a1" => ["un", "uno"], "a2" => ["uunn", "uunnoo"]}, 2 => {"b1" => ["deux", "dos"], "b2" => ["ddeuxx", "ddooss"]}}
hash.each do |key, key2, value|
puts key
hash[key].each do |key, value|
puts key
#insert here the code to iterate through the array
end
end
And this is the most logic thing that I found but that don't work:
hash = {1 => {"a1" => ["un", "uno"], "a2" => ["uunn", "uunnoo"]}, 2 => {"b1" => ["deux", "dos"], "b2" => ["ddeuxx", "ddooss"]}}
hash.each do |key, key2, value|
puts key
hash[key].each do |key, value|
puts key
hash[key][value].each do |value|
puts value
end
end
end