title: How to compare and print matching hash values in Ruby?
body: <p>I have two hashes like below,</p>
  
  <pre><code>h1 = {"a" =&gt; 1, "b" =&gt; 2, "c" =&gt; 3}
  h2 = {"a" =&gt; 2, "b" =&gt; 2, "d" =&gt; 3}
  </code></pre>
  
  <p>I want to iterate over hash1 and hash2 and find matching keys  and their values and print it on console.
  Example  here it should return output "b" => 2 .its not working with below code,</p>
  
  <pre><code>h1.each do |key1, value1|
  
    h2.each do |key2, value2|
      if ((h2.include? key1) &amp;&amp; (h2.include? value1))
        puts "matching h2 key #{h2[key2]}and h1 key #{h1[key1]}"
      else
        puts " don not match h2 key #{h2[key2]}and h1 key #{h1[key1]}"
      end
    end
  end
  </code></pre>
  
  <p>I am from basically C++ and Java background and its very easy to do using for loops and iterators, but using Ruby, it is very difficult.</p>