title: Ruby change the order of hash keys
body: <p>I have a hash and I would like the change the key order from.</p>
  
  <pre><code>{"result"=&gt;{"data"=&gt;[{"Quantity"=&gt;13, "Rate"=&gt;17.1},
                      {"Quantity"=&gt;29,"Rate"=&gt;3.2}, 
                      {"Quantity"=&gt;7, "Rate"=&gt;3.4}]}}
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>{"result"=&gt;{"data"=&gt;[{"Rate"=&gt;17.1, "Quantity"=&gt;13}, 
                      {"Rate"=&gt;3.2, "Quantity"=&gt;29}, 
                      {"Rate"=&gt;3.4, "Quantity"=&gt;7}]}}
  </code></pre>
  
  <p>that can be accessed by <code>hash["result"]["data"]</code>. I tried;</p>
  
  <pre><code>hash["result"]["data"][0].each_value{|v| v.replace({"Rate" =&gt; v.delete("Rate")}.merge(v))}
  </code></pre>
  
  <p>But it gives error: </p>
  
  <blockquote>
    <p>NoMethodError (undefined method `delete' for
     17.1:Float):</p>
  </blockquote>