On Fri, 14 Apr 2006, Jon B. wrote:

- operation and giving an error for those that don’t?

nothing. but try to write it. it’s harder than you might think.

you need to define as something like this:

class Range

def size

begin

first.distance last

rescue NoMethodError

begin

last.distance first

rescue NoMethodError

raise NoMethodError, “size”

end

end

end

end

class Fixnum

def distance other

(other - self).abs

end

end

class Float

def distance other

Float::MAX/Float::MIN # Infinity

end

end

in otherwords the endpoints must to the range size checking - otherwise

the

Range class would need to know about every class and how to calculate

sizes

for all M x N combinations.

if the endpoints calculate it we can easily do

(0 … 1).size

or

(0.0 … 1.0).size

but what about

(0 … 1.0).size

??

how does Range now which endpoint to use as ‘other’? if we use 1.0 it

works.

if we use 0 it does not.

it’s easy enough to fix this for only Fixnum and Float using a smart

coerce -

but then we have to deal with Rational, Bignum, Complex, String, etc.

and we

haven’t even hit user defined types.

i’m not saying there isn’t an elegant solution. but the problem becomes

evident imediately when one trys to solve the problem generically.

regards.

-a