title: How to assign an array of Hashes in a loop?
body: <p>I'm attempting to convert MySQL timestamps in an ActiveRecord object to another timestamp format. My method takes an array of ActiveRecord records and returns an array of hashes with the timestamped fields with the formatted timestamp: </p>
  
  <pre><code>def convert_mysql_timestamps(records)
      ary = []
      hash = {}
      records.each_with_index do |record, i|
        record.attributes.each do |field, value|
          if time_columns.include?(field) and value then
            hash[field] = value.strftime("%Y-%m-%dT%H:%M:%S%z")
          else
            hash[field] = value
          end
        end
        ary[i] = {}
        ary[i] = hash
      end
      ary
    end
  </code></pre>
  
  <p>However, when in the <code>ary[i] = hash</code> assignment, all <code>ary</code> elements get set to hash.</p>
  
  <p>Is there a better way to convert a record's timestamp fields? (I don't need to save the records back to the database.) Also, how can I get the array to capture each individual hash representation of the record?</p>
  
  <p>Input: </p>
  
  <pre><code>[#&lt;Vehicle id: 15001, approved_at: "2011-03-28 10:16:31", entry_date: "2011-03-28 10:16:31"&gt;, #&lt;Vehicle id: 15002, approved_at: "2011-03-28 10:16:31", entry_date: "2011-03-28 10:16:31"&gt;]
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>[{"id"=&gt;15001, "approved_at"=&gt;"2011-03-28T10:16:31-0700", "entry_date"=&gt;"2011-03-28T10:16:31-0700"}, {"id"=&gt;15002, "approved_at"=&gt;"2011-03-28T10:16:31-0700", "entry_date"=&gt;"2011-03-28T10:16:31-0700"}]
  </code></pre>