From: Josh Cheek Date: 2010-10-26T23:28:33+09:00 Subject: Re: embedded hash in array to selected-array --001485f6d476a2b24e049385eb08 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, Oct 26, 2010 at 8:55 AM, Kar=E1csony K. wrote: > Hi! > > I have this array: > users =3D [ { :id =3D> 1, :name =3D> 'Stephan'}, { :id =3D> 2, :name =3D> > 'Carol'}, { :id =3D> 3, :name =3D> 'Lizi'} ] > > How can i make a users_names, which will contain ['Stephan', 'Carol', > 'Lizi'] ? > Thanks:Koli > > -- > Posted via http://www.ruby-forum.com/. > > It seems you are using hashes to collect related data. If its just a quick one time use, a struct might be easier to work with. If you want something more robust, perhaps a class. User =3D Struct.new(:id ,:name) users =3D [ User.new(1,'Stephan') , User.new(2,'Carol') , User.new(3,'Lizi'= ) ] users # =3D> [#, #, #] users.map { |user| user.name } # =3D> ["Stephan", "Carol", "Lizi"] users.map { |user| user.id } # =3D> [1, 2, 3] --001485f6d476a2b24e049385eb08--