From: Dave Thomas Date: 2002-10-21T08:41:36+09:00 Subject: Re: Grouping by twos martindemello@yahoo.com (Martin DeMello) writes: > Another of those trivial little problems that I obsess about finding > the Proper way to do - what's a nice, idiomatic Ruby way to go from > [a,b,c,d.....] to [[a,b],[c,d],[e,f],...]? Note that I want to > preserve the ordering, so to_hash won't work. > > One way I thought of was > b = [] > while a[0] do > b << [a.shift, a.shift] > end This isn't much better, but b = [] b << a.slice!(0,2) until a.empty? Cheers Dave