title: Ruby Compare 2 hashes
body: <p>Is there a way to compare 2 hashes if the keys are not in the same order?  for instance </p>
  
  <pre><code>hash1 = { "it"=&gt; 10,"was"=&gt;11,"the"=&gt;14,"best"=&gt;1,"of"=&gt;12,"times"=&gt;2,
            "worst"=&gt;1,"age"=&gt;2,"wisdom"=&gt;1,"foolishness"=&gt;1,"epoch"=&gt;2,
            "belief"=&gt;1,"incredulity"=&gt;1,"season"=&gt;2,"light"=&gt;1,"darkness"=&gt;1,
            "spring"=&gt;1,"hope"=&gt;1,"winter"=&gt;1,"despair"=&gt;1,"we"=&gt;4,"had"=&gt;2,
            "everything"=&gt;1,"before"=&gt;2,"us"=&gt;2,"nothing"=&gt;1,"were"=&gt;2,"all"=&gt;2,
            "going"=&gt;2,"direct"=&gt;2,"to"=&gt;1,"heaven"=&gt;1,"other"=&gt;1,
            "way"=&gt;1,"in"=&gt;2,"short"=&gt;1,"period"=&gt;2,"so"=&gt;1,"far"=&gt;1,"like"=&gt;1,
            "present"=&gt;1,"that"=&gt;1,"some"=&gt;1,"its"=&gt;2,"noisiest"=&gt;1,
            "authorities"=&gt;1,"insisted"=&gt;1,"on"=&gt;1,"being"=&gt;1,
            "received"=&gt;1,"for"=&gt;2,"good"=&gt;1,"or"=&gt;1,"evil"=&gt;1,"superlative"=&gt;1,
            "degree"=&gt;1,"comparison"=&gt;1,"only"=&gt;1 }
  
  
  hash2 = {"superlative"=&gt;1, "it"=&gt;10, "going"=&gt;2, "spring"=&gt;1, "age"=&gt;2, 
           "despair"=&gt;1, "received"=&gt;1, "good"=&gt;1, "some"=&gt;1, "worst"=&gt;1, "was"=&gt;11,
           "only"=&gt;1,"us"=&gt;2, "evil"=&gt;1, "belief"=&gt;1, "for"=&gt;2, "darkness"=&gt;1,
           "comparison"=&gt;1, "short"=&gt;1, "in"=&gt;2, "present"=&gt;1, "direct"=&gt;2, "were"=&gt;2,
           "way"=&gt;1, "degree"=&gt;1, "or"=&gt;1, "of"=&gt;12, "epoch"=&gt;2, "incredulity"=&gt;1,
           "period"=&gt;2, "heaven"=&gt;1, "other"=&gt;1, "being"=&gt;1, "its"=&gt;2, "so"=&gt;1,
           "authorities"=&gt;1, "times"=&gt;2, "we"=&gt;4, "noisiest"=&gt;1, "light"=&gt;1, "hope"=&gt;1,
           "foolishness"=&gt;1, "everything"=&gt;1, "far"=&gt;1, "wisdom"=&gt;1, "season"=&gt;2, "like"=&gt;1,
           "before"=&gt;2, "had"=&gt;2, "the"=&gt;14, "nothing"=&gt;1, "winter"=&gt;1, "best"=&gt;1,
           "that"=&gt;1, "all"=&gt;2, "insisted"=&gt;1, "to"=&gt;1, "on"=&gt;1}
  </code></pre>
  
  <p>Each hash has the same keys. How would I go about comparing them and making sure that each key value is correct. All the questions and answers I've seen show hashes with the keys in the same order. Does it matter?  </p>
  
  <p>I've tried to use: </p>
  
  <p><code>hash1_1 = hash1.select{|k,_| hash2.has_key? k}</code></p>
  
  <p>which spit out: </p>
  
  <pre><code>{ "it"=&gt;10, "was"=&gt;11, "the"=&gt;14, "best"=&gt;1, "of"=&gt;12, "times"=&gt;2, 
       "worst"=&gt;1, "age"=&gt;2, "wisdom"=&gt;1, "foolishness"=&gt;1, "epoch"=&gt;2, 
       "belief"=&gt;1, "incredulity"=&gt;1, "season"=&gt;2, "light"=&gt;1, 
       "darkness"=&gt;1, "spring"=&gt;1, "hope"=&gt;1, "winter"=&gt;1, "despair"=&gt;1, 
       "we"=&gt;4, "had"=&gt;2, "everything"=&gt;1, "before"=&gt;2, "us"=&gt;2, "nothing"=&gt;1, 
       "were"=&gt;2, "all"=&gt;2, "going"=&gt;2, "direct"=&gt;2, "to"=&gt;1, "heaven"=&gt;1, 
       "other"=&gt;1, "way"=&gt;1, "in"=&gt;2, "short"=&gt;1, "period"=&gt;2, "so"=&gt;1, "far"=&gt;1, 
       "like"=&gt;1, "present"=&gt;1, "that"=&gt;1, "some"=&gt;1, "its"=&gt;2, "noisiest"=&gt;1, 
       "authorities"=&gt;1, "insisted"=&gt;1, "on"=&gt;1, "being"=&gt;1, "received"=&gt;1, 
       "for"=&gt;2, "good"=&gt;1, "or"=&gt;1, "evil"=&gt;1, "superlative"=&gt;1, "degree"=&gt;1, 
       "comparison"=&gt;1, "only"=&gt;1}
  </code></pre>
  
  <p>Please help me in explaining what I need to do.  Thank you. </p>