From: "Brian Schröder" Date: 2005-11-08T03:32:27+09:00 Subject: Re: an array of hashes On 07/11/05, Francesco wrote: > Hello all! > Can this be done better/nicer? > In @person i have an array of telephones. telephone is a hash with an id > and a number, and i would like to join them. > > @person.telephones.collect {|x| [] << x.number}.join(', ') > > I don't know why, but I don't like this line of code... how would you > write it? > > If telephone (x) is indeed a hash, the above would not work. It seems like telephone is a struct. Right? Then why don;t you do @person.telephones.map {|x| x.number}.join(', ') cheers, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/