[#407] New feature for Ruby? — Clemens.Hintze@...

Hi all,

27 messages 1999/07/01
[#413] Re: New feature for Ruby? — matz@... (Yukihiro Matsumoto) 1999/07/01

Hi Clemens,

[#416] Re: New feature for Ruby? — Clemens Hintze <c.hintze@...> 1999/07/01

On Thu, 01 Jul 1999, Yukihiro Matsumoto wrote:

[#418] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/01

Hi

[#426] Re: New feature for Ruby? — gotoken@... (GOTO Kentaro) 1999/07/02

Hi,

[#440] Now another totally different ;-) — Clemens Hintze <c.hintze@...>

Hi,

21 messages 1999/07/09
[#441] Re: Now another totally different ;-) — matz@... (Yukihiro Matsumoto) 1999/07/09

Hi,

[#442] Re: Now another totally different ;-) — Clemens Hintze <c.hintze@...> 1999/07/09

On Fri, 09 Jul 1999, you wrote:

[#443] — Michael Hohn <hohn@...>

Hello,

26 messages 1999/07/09
[#444] interactive ruby, debugger — gotoken@... (GOTO Kentaro) 1999/07/09

Hi Michael,

[ruby-talk:00440] Now another totally different ;-)

From: Clemens Hintze <c.hintze@...>
Date: 1999-07-09 05:15:34 UTC
List: ruby-talk #440
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

In This Thread

Prev Next