title: How to sort an array in descending order in Ruby
body: <p>I have an array of hashes:</p>
  
  <pre><code>[
    { :foo =&gt; 'foo', :bar =&gt; 2 },
    { :foo =&gt; 'foo', :bar =&gt; 3 },
    { :foo =&gt; 'foo', :bar =&gt; 5 },
  ]
  </code></pre>
  
  <p>I am trying to sort this array in descending order according to the value of <code>:bar</code> in each hash.</p>
  
  <p>I am using <code>sort_by</code> to sort above array:</p>
  
  <pre><code>a.sort_by { |h| h[:bar] }
  </code></pre>
  
  <p>However, this sorts the array in ascending order. How do I make it sort in descending order?</p>
  
  <p>One solution was to do following:</p>
  
  <pre><code>a.sort_by { |h| -h[:bar] }
  </code></pre>
  
  <p>But that negative sign does not seem appropriate.</p>