From: Ilan Berci Date: 2007-10-20T05:50:23+09:00 Subject: Re: What's the ruby way of grouping elements of an array? Sam Kong wrote: > > The above method should return an array of arrays grouped by age. > > What's the ruby way for this case? > I think I can implement it but I am sure that a good way already exists. > > Thanks. > > Sam If you require 'action_pack' you get group_by() for free >> Array.new(20) {Kernel.rand(20)}.group_by {|age| age > 10} => {false=>[9, 5, 3, 6, 0, 8, 3, 4, 9, 2, 0, 0, 10, 1], true=>[15, 13, 18, 12, 13, 14]} >> hth ilan -- Posted via http://www.ruby-forum.com/.