From: Robert Klemme Date: 2005-08-29T16:09:43+09:00 Subject: Re: [Q] how to unflatten a flat-array 2005/8/29, SHIGETOMI, Takuhiko : > dear guys, > > i am seeking a smart way to do ... > > [ 1, 2, 3, 4, 5, 6, ... ] => [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], ... ] > > especialy, the way hopefully will work safety when the source array's > size is odd or zero. This is a pretty much straightforward implementation: >> res=[]; 0.step(a.length - 1,2) {|i| res << [a[i],a[i+1]]}; res => [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]] Kind regards robert