On 10/19/06, Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> Hi,
>
> In message "Re: String not enumerable, what about IO? (was Re: Symbol < String in Ruby > 1.8)"
>     on Thu, 19 Oct 2006 20:36:28 +0900, dblack / wobblini.net writes:
>
> |Otherwise -- if lines is an enumerator, rather than some lines -- it
> |feels to me like Ruby is taking over too much.  It's as if I'm being
> |allowed to say "I want lines from this string", but Ruby knows better:
> |I don't *really* want lines, even if I think I do.
> |
> |That kind of steering away from the semantics of the method names
> |makes me uncomfortable.  If I need an enumerator, I want the language
> |to give me a way to ask for one clearly; and if I ask for "things", I
> |want the things.
>
> Hmm, maybe the name Enumerator does not make you feel like it's a
> collection.  What if Enumerator is renamed to some other name, for
> example, DelayedCollection or something?

I was going to reply to David's post that an Enumerator can be viewed
as a collection, it enumerates the same elements as the base
collection would when sent the message represented by the symbol used
to create it.

The main difference between, say, an array, and an enumerator on an
array is that the enumerator can't be indexed directly.

The case for each returning an Enumerator when a block is not given
might not be as clear as, say, Hash#each_key doing it, but I like the
uniformity that all each* method would do this.

As for actually renaming Enumerator to DelayedCollection, I'm not so
enamored of that, since again, I don't think that breaking old code
unnecessarily is a good thing, and Enumerator is already there albeit
part of the standard library rather than the core, but aside from not
needing the require 'enumerator' I appears to look pretty much the
same between 1.8 and 1.9.

Now I suppose that my argument could be turned against having these
methods returning an enumerator when a block is not given is a change
from 1.8. But I can't think of how the old behavior was useful.  Maybe
it's a lack of imagination on my part.  In any case, the 1.8 behavior
seems to be inconsistent anyway.

$ irb
irb(main):001:0> {}.each_key
=> {}
irb(main):002:0> {}.each
=> {}
irb(main):003:0> [].each
=> []
irb(main):004:0> "abc".each
LocalJumpError: no block given
        from (irb):4:in `each'
        from (irb):4

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/