title: How does <=> work for different sorting strategies?
body: <p>I'm going through some tutorials on CodeAcademy, and came across this scenario:</p>
  
  <pre><code>books = ["Charlie and the Chocolate Factory", "War and Peace", "Utopia", "A Brief History of Time", "A Wrinkle in Time"]
  
  # To sort our books in ascending order, in-place
  books.sort! { |firstBook, secondBook| firstBook &lt;=&gt; secondBook }
  
  
  # Sort your books in descending order, in-place below
  # this lin initially left blank
  books.sort! {|firstBook, secondBook| secondBook &lt;=&gt; firstBook}
  </code></pre>
  
  <p>Instead of using <code>if</code>/<code>else</code> blocks, I gave this a shot, and it worked, but I don't know why. I assume it doesn't matter which order you place the items in the check (i.e., <code>a &lt;=&gt; b</code> vs. <code>b &lt;=&gt; a</code>). Could someone explain what's happening here?</p>