On Nov 20, 2006, at 10:50 AM, Ross Bamford wrote: > On Mon, 20 Nov 2006 15:33:33 -0000, David Lelong > <drlelon / yahoo.com> wrote: > >> Hi, >> >> I have a hash that contains the following keys/values: >> >> [#<Contact_List:0x2607150 @attributes={"contact_id"=>"4"}>, >> #<Contact_List:0x2607114 @attributes={"contact_id"=>"8"}>] >> >> I want to create an array containing the contact_id values. >> What's an >> easy way to do this? >> >> Thanks, >> >> David >> > > Assuming Contact_List (aside: why an underscored class name?) has > an attr_accessor for 'attributes', you might try: > > a.map { |clist| clist.attributes['contact_id'] } > > (where 'a' is the array you show above). > > -- > Ross Bamford - rosco / roscopeco.remove.co.uk Well, the OP asked for easy and what's easier than Symbol#to_proc (or am I reading Rails and ActiveRecord into this question where it's missing?) a = [#<Contact_List:0x2607150 @attributes={"contact_id"=>"4"}>, #<Contact_List:0x2607114 @attributes={"contact_id"=>"8"}>] a.map(&:contact_id) => [4, 8] -Rob Rob Biedenharn http://agileconsultingllc.com Rob / AgileConsultingLLC.com