From: Christoph Date: 2002-04-30T19:45:15+09:00 Subject: Re: [RFC] Ranges - enable (10..-10) "David Alan Black" wrote in .... > In [ruby-talk:8993], matz said: > > The truth are: > > * A range enumeration cannot go back, it's upward only. > > * But A range with end point less than start point is valid. > > * Thus 1..-1 is a completely valid range object. > > * Array and String internally convert negative end point into > size+n, where n is a negative number. > > * So range n..-m is interpreted as n..(size-m), thus works fine (if > n <= (size-m)). > > I can't claim I've totally grasped why a range is upward by > definition... but apparently it is, so that's *my* problem :-) You'll You might find the following example somewhat enlighting? --- class Class alias succ superclass end p (Fixnum..Object).to_ary # => [Fixnum, Integer, Numeric, Object] begin (Fixnum..UnboundMethod) # Fixnum and UnboundMethod are not comparable rescue ArgumentError => mes p mes # => # end --- Given the fact that empty Ranges ala (1..-2) and (1...-2) are valid construct, it would makes to extend the Range construction and declare (Fixnum..UnboundMethod).to_ary == [Fixnum, Integer, Numeric, Object] (Fixnum..Float).to_ary == [Fixnum, Integer, Numeric] # and (Fixnum...UnboundMethod).to_ary == [] (Fixnum...Float).to_ary == [] # or (?) (Fixnum...UnboundMethod).to_ary == [Fixnum, Integer, Numeric] (Fixnum...Float).to_ary == [Fixnum, Integer] Note I am not at all lobbying for such a behavioral change. /Christoph