From: William James Date: 2006-07-21T05:35:05+09:00 Subject: Re: how to split an array in sub arrays of the same length Paolo Bacchilega wrote: > Hi, > > Is there a way to split an array in sub arrays of the same length, that > is : > > [ 1, 2, 3, 4, 5, 6, 7, 8 ].unknown_function(3) > > that returns: > > [ [1, 2, 3], [4, 5, 6], [7, 8] ] > > > thanks in advance. Always remember that a program without inject is a pointless program. [ 1, 2, 3, 4, 5, 6, 7, 8 ].inject([[]]){|a,x| a.last.size<3 ? a.last << x : a << [x]; a }