----- Original Message -----
From: <dblack / wobblini.net>

> > What I would prefer (and this would probably be a major change to the
> > implementation) is to be able to treat ALL enumerable classes as Arrays.
In
> > other words, I'd like to suggest that Array and Enumerable effectively
be
> > the same thing, and that "Array" would be the superclass instead of
> > "Enumerable".
>
> Enumerable isn't a superclass; it's a module.  Don't forget you can
> mix it in to your own classes, so it's not just a matter of the
> behavior of Ruby core classes that are Enumerable.
>
> Also, in some respects Array is the common currency of Enumerables, in
> the sense that a lot of Enumerable methods return arrays.  But that
> doesn't mean that Array itself is more Enumerable, so to speak, than
> other Enumerable classes.

I take your point about Enumerable being a module. I guess I said it badly,
but I am trying to reconcile the way an Array works with that of an
arbitrary Enumerable. They are similar, yet (at times) frustratingly
different.

1) There are several methods in Array which I think could (should?) also be
in Enumerable (eg: uniq, +, | etc).

2) Presumably, as an alternative to most of the Enumerable methods, you
could use "to_a", and then use Array methods. I guess the Enumerable methods
would be more efficient than doing this, so is that the reason for using
them, or is it brevity or something else?

3) It has been mentioned before that Enumerable is a collection, which is
unordered (ie: you can't index them). However characters or lines in a
string or file *are* ordered. When you iterate over them you expect them to
come back in order.

4) Other posts proposed having String#lines & String#bytes return an Array,
so the same efficiency comment as (2) applies. They could also return an
Enumerable object, which maybe more efficient but this relies on "each"
returning them in order (which it probably would!).

What I was getting at is that much of the time Enumerables *are* ordered,
whether we need it or not. If we accept this, it makes sense, for example,
to make things like "reverse" an Enumerable method.

So why not make Enumerables indexable also? Presumably the base method would
have to define the "[]" method to do this, but it would be sort of nice to
efficiently index the n'th line in a string or m'th record in a file using
Array style syntax without having to convert the whole thing to an array.
You could even go the whole hog, and use "[]=" to make virtually all the
Array methods available (delete, insert etc). May be a new module, rather
than polluting Enumerable?

Does that make sense?

Mike.