On 06.06.2007 00:40, Kenneth McDonald wrote:
> Oops, my bad, I saw the class being reopened and jumped to a conclusion 
> without even looking at the code. Thanks for pointing this out.
> 
> But I still wish it were possible to write (3...1) and have it do 
> something that (IMHO) would be a bit more useful than the current 
> behavior. :-) Oh well, too late now.

The real issue here is that there are at least two useful ways to deal 
with ranges where the second element lies before the first one:

1. no iteration

This is useful for scenarios where you somehow determine the end point 
and you want to iterate only if it is to the right of the starting 
point.  For example

def show_silly_example(s, start, char)
   (start .. s.index(char)).each do |i|
     puts s[i]
   end
end

2. backwards iteration

This is useful when you want to be able to do backward iteration.

Given the fact that not foo all possible range endpoints there is a 
meaningful #pred method, I guess option 1 is actually a better choice:

irb(main):012:0> "ab".succ
=> "ac"
irb(main):013:0> "ab".pred
NoMethodError: undefined method `pred' for "ab":String
         from (irb):13
         from :0
irb(main):014:0>

IMHO a ReverseRange class would be good, but at the moment I cannot 
think of a compelling syntax that would make creation as straightforward 
as for Range.

Kind regards

	robert