In message "[ruby-talk:00467] Re: Now another totally different ;-)"
on 99/07/12, Yukihiro Matsumoto <matz / netlab.co.jp> writes:
>|And whether it has a different meaning or not, depends from your
>|point of view! You may see it as: The method `[]' delivers the
>|element stored under the index. Array elements are indexed by its
>|position, Hash elements by its key, etc. So `[]' works equal to both
>|classes. Or what do you think?
>
>Hmm, I'm curious what others think about this matter.
>Don't care?
If I may use metaphor, `[]' reminds me a baggage keeper, who fetches a
specified baggage from a storeroom. On the other hand, `each' is her
own way to treat in the storeroom one by one. In this sense, I think
that `[]' doesn't have the natural relation to `each' for caller-side,
because `each' is just a receiver's business and I hope that `[]' does
NOT depend on such an internal action. I don' wanna specify a object
by a magic number!
Indeed, I often define `Integer[1.0]' instead of `Integer(1.0)',
# Do you remember it, Matz?
or My::Matrix[Float] to make a Matrix class which is restricted its
contents to Float. Even in this cases, they can be considered
enumerable if I define `each' for them.
Of course, one can define `[]' via `each'. I can't ban doing that :-)
# Don't be fed up with my obstinacy, Cle.
-- gotoken