title: How to preserve alphabetical order of keys when sorting a hash by the value
body: <p>beginner here. My first question. Go easy on me.</p>
  
  <p>Given the following hash:</p>
  
  <pre><code>pets_ages = {"Eric" =&gt; 6, "Harry" =&gt; 3, "Georgie" =&gt; 12, "Bogart" =&gt; 4, "Poly" =&gt; 4,
          "Annie" =&gt; 1, "Dot" =&gt; 3}
  </code></pre>
  
  <p>and running the following method:</p>
  
  <pre><code>pets_ages.sort {|x, y| x[1] &lt;=&gt; y[1]}.to_h
  </code></pre>
  
  <p>the following is returned:</p>
  
  <pre><code>{
        "Annie" =&gt; 1,
          "Dot" =&gt; 3,
        "Harry" =&gt; 3,
         "Poly" =&gt; 4,
       "Bogart" =&gt; 4,
         "Eric" =&gt; 6,
      "Georgie" =&gt; 12
  }
  </code></pre>
  
  <p>You will notice the hash is nicely sorted by the value, as intended. What I'd like to change is the ordering of the keys, so that they remain alphabetical in the case of a tie. Notice "Dot" and "Harry" are correct in that regard, but for some reason "Poly" and "Bogart" are not. My theory is that it is automatically sorting the keys by length in the case of a tie, and not alphabetically. How can I change that?</p>