From: William James Date: 2007-09-08T06:05:05+09:00 Subject: Re: array handling advice On Sep 7, 3:32 pm, Erik Veenstra wrote: > For better readability, define it in a library. And if it's > defined in a library, well, you might want to write the > implementation in a readable way... :} > > gegroet, > Erik V. -http://www.erikveen.dds.nl/ > > ---------------------------------------------------------------- > > module Enumerable > def group_by_size(size) > res = [] > > each_with_index do |o, n| > res << [] if n%size == 0 > > res[-1] << o > end > > res > end > end > > a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > b = a.group_by_size(3) > > p a > p b > > ---------------------------------------------------------------- 1. Doesn't enum_slice do this? 2. This isn't what the o.p. wants.