how to traverse two hashes simultaneously ruby

I have two hashes and I want to traverse both of them. How can I traverse them simultaneously.

hash1 = {"key1" =>"value1", "key2" => "value2"}
hash2= {"key3" => "value3", "key4" => "value4"}

hash1.each do |k1,v1|
  hash2.each do |k2,v2|
    #do something with k1 and k2 (which is key1 and key3, then key1 and key4 for first iteration of hash1 and key2 and key3, then key2 and key4 for second iteration of hash1)
  end
end 

This is what I’m doing right now. Is there any other idiomatic or better way


Source: ruby

Leave a Reply