From: Brian Candler Date: 2004-10-09T20:51:30+09:00 Subject: Re: Range behavior (Re: [RCR] New [] Semantics) On Sat, Oct 09, 2004 at 08:14:42PM +0900, gabriele renzi wrote: > Randy W. Sims ha scritto: > > >Or better. Some classes could implement an optional method (a mixin > >interface?), say find_in_range, so that if the method exists for the > >type of objects in the range it is called for an efficient lookup. If > >the object does not support the method, it can be done the old way using > >obj#succ. > > isn't <=>+checking for same class enough for this? At the moment, (3..5).member?(3.5) #=> false (3..5).member?(4.0) #=> true so following your rule exactly wouldn't duplicate the current behaviour. You'd need some way of saying "is there some Integer x where x == 4.0" Or I suppose more generally: (a..b).member?(c) is true if a <= b <[=] c and there exists some d such that c == d and d.instance_of?(a.class) Except - some ranges change class as they iterate, e.g. if 'a' is a Fixnum and 'b' is a Bignum. Ugh! Regards, Brian.