From: SunRaySon Date: 2007-02-09T05:09:13+09:00 Subject: Re: Grouping similar attributes ------=_Part_15056_4635323.1170965348529 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline This can help you too... def ethnic_group(e, n) if @eg.nil? @eg = {} end if @eg[e].nil? @eg[e] = [] end @eg[e] << n return @eg end @eg = nil ethnic_group('asian', 'domnic') ethnic_group('asian', 'john') ethnic_group('spanish', 'rich') p @eg On 2/8/07, Dominic Son wrote: > > How would one group attributes which came from an array/db? > > For example in my DB: > > --------------------- > | NAME | ETHNIC | > -------------------- > | Dominic | Asian | > --------------------- > | John | Asian | > --------------------- > | Rick | Spanish | > --------------------- > > I'd like it to group by Ethnicity: > > Asian > - Dominic > - John > > Spanish > - Rich > > > Is there some ruby thing that makes this convenient? > > Thanks a whole bunch. > > Dominic > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_15056_4635323.1170965348529--