Hi,
during my journey according class Interval (now renamed to Sequence),
I have found two quirks.
1. I think that the mix-in module Enumeration, could also offer a
method `[]', as that is easy possible to realize via `each'. In Ruby
I could implement it as:
def [](index)
i = 0
each do |element|
return element if i == index
i += 1
end
nil
end
Of course, classes should reimplement it more performant if possible.
But now, every class include Enumeration, would automatically be
indexable via `[]'. Furthermore we already have Enumeration#index and
Enumeration#to_a. So now I can use `any.to_a[3]' but I feel `any[3]'
would be better.
2. The operators `..' and `...' cannot be overwritten! If I define
class Fixnum
def ..(e)
print "Blabla"
end
end
and call it with `2..4' it will results in a Range object, instead of
printing only "Blabla". A look into the code has shown me, that
`rb_range_new' would be called directly on C-level if `..' or `...'
are send. But I can overwrite e.g. Fixnum#+. I think that is a
serious flaw, which will retrict one. It should all be handled in
the same manner. So I would propose, that these operators also have to
send a message to the receiver. And the receiver has to instantiate a
Range object, if desired!
Any opinions welcomed :-)))))
\cle