James Gray
2/1/2007 8:55:00 PM
On Feb 1, 2007, at 2:49 PM, Giant Cranes wrote:
> I have an array of hashes as follows:
>
> a = Array.new
> a << {:name => 'tony', :age => 23}
> a << {:name => 'mary', :age => 57}
> a << {:name => 'dom', :age => 17}
>
> I am trying to create an array with one attribute from each hash:
>
> ['tony', 'mary', 'dom']
>> a = Array.new
=> []
>> a << {:name => 'tony', :age => 23}
=> [{:name=>"tony", :age=>23}]
>> a << {:name => 'mary', :age => 57}
=> [{:name=>"tony", :age=>23}, {:name=>"mary", :age=>57}]
>> a << {:name => 'dom', :age => 17}
=> [{:name=>"tony", :age=>23}, {:name=>"mary", :age=>57},
{:name=>"dom", :age=>17}]
>> a.map { |e| e[:name] }
=> ["tony", "mary", "dom"]
Hope that helps.
James Edward Gray II