On Sep 20, 2007, at 2:28 PM, Sammy Larbi wrote:

> 1) Would it make sense to talk about a Range having a length, as in:
>
> class Range
>       def length
>            self.end - self.begin
>       end
> end

A range only assumes #<=> and #succ.

Thus, the only sensible definable length given those basic pieces  
would be "number of elements", computed looping over the collection.  
A length computed as a difference max - min is not guaranteed to make  
sense in a range because the elements may not respond to #-.

On the other hand note that the definition of Range does not imply  
the collection is finite, given suitables #<=> and #succ a range can  
represent an enumeration of the rationals in [0, 1]. So strictly  
speaking "number of elements" defined with that procedure does not  
apply to all ranges either.

-- fxn