From: Brian Candler Date: 2003-05-30T23:26:21+09:00 Subject: Re: Iteration - last detection On Fri, May 30, 2003 at 10:09:39PM +0900, Carlos wrote: > > I must be missing something; why is this not an incredibly simple thing to > > achieve? > > > > module Enumerable > > def each_with_last > > The methods in Enumerable don't call #each_with_last, they call > #each... But now it seems that they don't call #each either :-/. I don't follow. The pickaxe says: module Enumerable Relies on: each, <=> The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection. So they only rely on the existence of 'each', unless you are using sort/min/max. I thought the question was "how do I get a method like 'each', but which includes a flag saying whether this is the last element or not?" In which case, you just define another method which does that, called (say) 'each_with_last', which makes use of 'each'. Where does this fail? Cheers, Brian.