From: "SHIGETOMI, Takuhiko" Date: 2005-08-29T11:44:01+09:00 Subject: Re: [Q] how to unflatten a flat-array greetings, David. how nice it is! > I've got a method from long ago that might fit: > > class Array # or do it as a module, or whatever > def in_slices_of(n) > res = [] > 0.step(size - 1, n) do |i| > s = slice(i...i + n) > yield s if block_given? > res.push s > end > res > end > end > > [1,2,3,4,5,6].in_slices_of(2) # => [[1, 2], [3, 4], [5, 6]] > [1,2,3,4,5,6].in_slices_of(3) # => [[1, 2, 3], [4, 5, 6]] > > It handles odd numbers by putting whatever's left over in its own > array: > > [1,2,3,4,5,6,7].in_slices_of(2) # => [[1, 2], [3, 4], [5, 6], [7]] quick question. (sorry, i am still screwed up.) will the yieldee ( = the block ) 's 2nd parameter be nil at the end of the case of odd number as above ? -- SHIGETOMI,Takuhiko tshiget1@gw.nsw.co.jp /void/3d/universe/milkyway-galaxy/orion's-arm/sol-solar-system/3rd-planet/fareast/jp/tky/ resistance is futile.