From: martindemello@... (Martin DeMello) Date: 2002-10-22T05:34:47+09:00 Subject: Re: Grouping by twos "Allen Mitchell" wrote in message news:... > I ran into the same requirement and I solved it by extending the Array > class. Have a look... Neat. Getting positively verbose, but here's an extension to Enumerable module Enumerable def eachn(n) a = [] if block_given? each {|i| a << i if a.length == n yield a a = [] end } yield a unless a.empty? #possibly padded with nils else b = [] eachn(n) {|i| b << i} b end end end a = (1..10).to_a b = a.eachn(2) puts a.inspect, # => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] b.inspect # => [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]