From: Joel VanderWerf Date: 2007-01-08T15:02:31+09:00 Subject: Re: Grouping elements of an array? Farrel Lifson wrote: > On 08/01/07, Sam Kong wrote: >> What's the best way to do the following? >> >> [1,2,3,4,5,6,7,8,9] => [[1,2,3],[4,5,6],[7,8,9]] ... > [1,2,3,4,5,6,7,8,9].enum_slice(3).inject([]){|array,slice| array << slice} Alternately, [1,2,3,4,5,6,7,8,9].enum_for(:each_slice,3).to_a => [[1, 2, 3], [4, 5, 6], [7, 8, 9]] -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407