Robert Klemme
11/7/2006 2:16:00 PM
On 07.11.2006 14:21, Jan Svitok wrote:
> On 11/7/06, Brad Tilley <rtilley@vt.edu> wrote:
>> Say I have an array that contains 144 strings. I want to divide the
>> array into
>> 12 sub-arrays each containing 12 strings. What is the Ruby Way of
>> doing this?
>> I've looked at slice array[0..11] etc, but that seems a bit clunky.
>
> require 'enumerator'
>
> ret = []
> array.each_slice(12) {|a| ret << a}
require 'enumerator'
arr = Array.new 144, "x"
ret = arr.to_enum(:each_slice, 12).inject([]) {|a, *x| a << x}
Kind regards
robert