title: How to sort a Ruby Hash by number value?
body: <p>I have a counter hash that I am trying to sort by count. The problem I am running into is that the default Hash.sort function sorts numbers like strings rather than by number size.</p>
  
  <p>i.e. Given Hash:</p>
  
  <pre><code>metrics = {"sitea.com" =&gt; 745, "siteb.com" =&gt; 9, "sitec.com" =&gt; 10 }
  </code></pre>
  
  <p>Running this code:</p>
  
  <pre><code>metrics.sort {|a1,a2| a2[1]&lt;=&gt;a1[1]}
  </code></pre>
  
  <p>will return a sorted array:</p>
  
  <pre><code>[ 'siteb.com', 9, 'sitea.com', 745, 'sitec.com', 10]
  </code></pre>
  
  <p>Even though 745 is a larger number than 9, 9 will appear first in the list. When trying to show who has the top count, this is making my life difficult. :)</p>
  
  <p>Any ideas on how to sort a hash (or an array even) by number value size?</p>
  
  <p>I appreciate any help.</p>