From: Rick DeNatale Date: 2010-04-01T08:24:08+09:00 Subject: Re: each_slice() On Wed, Mar 31, 2010 at 6:45 PM, Albert Schlef wrote: > Albert Schlef wrote: >> If *you* where using each_slice(), what versions of Ruby would you limit >> your gem to? > > I searched the net and it seems it's only safe to use each_slice() in > Ruby 1.9, I think. But I need my code to work in 1.8 as well. > > Anybody has an idea how to rewrite the following code > >  some_array.each_slice(2).to_a > > so that it works in Ruby 1.8 too? require 'enumerator' ruby -v ruby 1.8.7 (2009-12-24 patchlevel 248) irb irb(main):001:0> require 'enumerator' => false irb(main):002:0> (1..6).to_a.each_slice(2).to_a => [[1, 2], [3, 4], [5, 6]] -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale