title: Ruby CSV::Table sort in place
body: <p>I'm sorting a <code>CSV::Table</code> object. I have a table with headers (<code>"date"</code>, <code>"amount"</code>, <code>"source"</code>) and <code>O(50)</code> entries.</p>
  
  <p>Input:</p>
  
  <pre><code>data = CSV.table('filename.csv', headers:true) # note headers are :date, :source, :amount
  
  amounts = []
  data[:amount].each {|i| amounts &lt;&lt; i.to_f}
  
  data.sort_by! {|row| row[:amount]} 
  # error - not a defined function
  
  data = data.sort_by {|row| row[:amount]} 
  # sorted but data is now an array not CSV::Table. would like to retain access to headers
  </code></pre>
  
  <p>I want a bang function to sort the table in place by the <code>"amount"</code> column without loosing the <code>CSV::Table</code> structure.  Specifically, I want the result to be a CSV::Table, so that I still have access to the headers.  Right now, I'm getting an Array, which is not what I want.</p>
  
  <p>I'm sure there is an easier way to do this, especially with the <code>CSV::Table</code> class. Any help?</p>