title: How does Array#sort work when a block is passed?
body: <p>I am having a problem understanding how <code>array.sort{ |x,y| block }</code> works exactly, hence how to use it?</p>
  
  <p>An example from <a href="http://ruby-doc.org/core-2.1.1/Array.html#method-i-sort" rel="noreferrer">Ruby documentation</a>:</p>
  
  <pre><code>   a = [ "d", "a", "e", "c", "b" ]
     a.sort                     #=&gt; ["a", "b", "c", "d", "e"]
     a.sort { |x,y| y &lt;=&gt; x }   #=&gt; ["e", "d", "c", "b", "a"]
  </code></pre>