From: Christopher Dicely Date: 2010-09-04T04:56:00+09:00 Subject: Re: Enumerator#each return value is surprising On Fri, Sep 3, 2010 at 8:40 AM, Yossef Mendelssohn wrote: > > You should learn to expect the original array as a return value. It's > not about what kind of `each` enumeration you use, but the ability to > chain calls as expected. I think that is exactly what gets broken, though: Enumerator is the only core Ruby class that mixes in Enumerable on which chained calls to #each do not each get sent to the same receiver. To me, this seems to be a leaky abstraction that adds a subtle potential complication to code that operates on Enumerables. > If you want to get something different, use a > transforming enumerator instead of `each`. I understand HOW the existing operations work. What I'm trying to understand is the rationale, in part because I'm working on doing some work on implementing some extensions to Enumerable to provide some a few additional querying/joining operations over Ruby Enumerables (vaguely like LINQ to Objects in .NET.) Naturally, this involves implementing custom Enumerators. My inclination has always been that custom Enumerables should behave like Ruby's core enumerables (except, I now realize, Enumerator) and return the receiver from #each for consistency. Since the core enumerators don't do that, though, I'd like to avoid an implementation that is going to violate the expectations of Enumerators.