From: Peter Szinek Date: 2006-11-21T00:43:24+09:00 Subject: Re: Create array of hash values Peter Szinek wrote: > David Lelong wrote: >> Hi, >> >> I have a hash that contains the following keys/values: >> >> [#"4"}>, >> #"8"}>] >> >> I want to create an array containing the contact_id values. What's an >> easy way to do this? > > Try this: > > result = x.inject([]) {|a,h| a << h.values[0]; a} Sorry I have overlooked a little detail... My solution would work if the original array would contain [{"contact_id"=>"4"}, {"contact_id"=>"8"}] For the original question, the answer should be probably result = x.inject([]) {|a,h| a << h.attributes.values[0]; a} HTH, Peter __ http://www.rubyrailways.com