From: botp Date: 2010-06-02T10:16:10+09:00 Subject: Re: enumerator problem in 1.9.1 On Wed, Jun 2, 2010 at 3:45 AM, Robert Dober wrote: > On Tue, Jun 1, 2010 at 7:32 PM, Bug Free wrote: >> Robert Dober wrote: >>> I am afraid that is incorrect :( >>> ruby -ve '[5, 7].each_with_index.each {|a| p a}' >>> ruby 1.9.2dev (2010-05-31 revision 28117) [i686-linux] >>> 5 >>> 7 >> >> However, with the each_cons we get: >> >> ruby -ve '[5, 7].each_with_index.each_cons(2) {|a| p a}' >> ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-linux] >> [[5, 0], [7, 1]] >> -- > Funny indeed... ah, ok, now i know where i'm confusing myself, and in turn, all of you :) i've always thought that to capture the index of each_with_index (and it's siblings) you'll have to explicitly specify the index or use the splat op. this is because (my thoughts only emphasized again) ruby will passed the whole args to the block splatted (w index as the last arg), so you'll have to call the splat again to unsplat it. for each_cons, the block arg is arrayed/unsplatted, so you get the whole args. again, just my usual primitive thoughts. Works for me all the time, and never thought about it again until now. As to whether i should change the way i think about each_with*, no problem, this is ruby :) thanks and kind regards -botp