Fetch ActiveRecord query result as an array of hashes with chosen attributes
<p>The model <code>User</code> has <code>first</code>, <code>last</code> and <code>login</code> as attributes. It also has a method called <code>name</code> that joins <code>first</code> and <code>last</code>.</p>

<p>What I want is to iterate through the <code>Users</code> records and create an array of hashes with the attributes I want. Like so:</p>

<pre><code>results = []
User.all.map do |user|
    record = {}
    record["login"] = user.login
    record["name"] = user.name
    results &lt;&lt; record
end
</code></pre>

<p>Is there a cleaner way in Ruby to do this?</p>