From: Robert Klemme Date: 2010-11-19T18:37:36+09:00 Subject: Re: Descending ranges in Ruby On Fri, Nov 19, 2010 at 5:49 AM, Harry Spier wrote: > Thanks for this work-around but my question was not so much how to get > around this restriction but rather "why I'm restricted from iterating > over a descending range if descending Ranges are legal?".  For example a > Range returned by a function in my program that I may not know whether > it is ascending or descending? IIRC a Range finds the next value via #succ. And Fixnum#succ always yields the next higher number. If you want to use a Range you must use a type which reverses #succ and #<=>, example: irb(main):001:0> RFN = Struct.new :value do irb(main):002:1* def <=>(o) o.value <=> value end irb(main):003:1> def succ; self.class.new(value - 1) end irb(main):004:1> end => RFN irb(main):005:0> (RFN.new(5) .. RFN.new(1)).to_a => [#, #, #, #, #] I'd rather stick with the other approaches presented or use Array#reverse. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/