title: Hash/Ruby - Select last 4 values (to average) in hash
body: <p>I have a hash, that I select all the data for a dashboard to display performance, since displaying the latest value isn't always helpful, I'm trying to select the last 4 values from a hash. </p>
  
  <p>I have attempted the <code>thing.last(4)</code>, but to no avail.</p>
  
  <p>Code is below, essentially trying to display the last 4 from <code>top_points</code>, or average points.</p>
  
  <p>Note: Ruby 1.9</p>
  
  <pre><code>metric.sort.each do |key, value|
    top_point = { x: Time.parse(key).to_time.to_i, y: value['top_10'] }
    top_points &lt;&lt; top_point
  
    average_point = { x: Time.parse(key).to_time.to_i, y: value['average'] }
    average_points &lt;&lt; average_point
  end
  </code></pre>