From: "David A. Black" Date: 2005-08-29T20:51:50+09:00 Subject: Re: [Q] how to unflatten a flat-array Hi -- On Mon, 29 Aug 2005, SHIGETOMI, Takuhiko wrote: > greetings, Daniel. true. 'next' works. > >> You can't easily go backwards, but skipping to the next is >> as easy as saying `next'. > > on the other hand, and as your reference 'cannot easyily go backwards', > 'next' forgets current object unless any variable on outside of the > yieldee block. > > how about writing a special yielder like as below .. > > any-enumerable-object.sliding_each do |prev,this,next| > ... > end > > - could be really useful? > - any other good name? This might help you on this: irb(main):003:0> require 'enumerator' => true irb(main):004:0> [1,2,3,4,5,6].each_cons(2) {|x| p x } [1, 2] [2, 3] [3, 4] [4, 5] [5, 6] => nil irb(main):005:0> [1,2,3,4,5,6].each_cons(3) {|x| p x } [1, 2, 3] [2, 3, 4] [3, 4, 5] [4, 5, 6] David -- David A. Black dblack@wobblini.net