On Fri, Nov 19, 2010 at 5:49 AM, Harry Spier <harryspier / hotmail.com> 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?". =A0For 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 #<=3D>, example:

irb(main):001:0> RFN =3D Struct.new :value do
irb(main):002:1* def <=3D>(o) o.value <=3D> value end
irb(main):003:1> def succ; self.class.new(value - 1) end
irb(main):004:1> end
=3D> RFN
irb(main):005:0> (RFN.new(5) .. RFN.new(1)).to_a
=3D> [#<struct RFN value=3D5>, #<struct RFN value=3D4>, #<struct RFN
value=3D3>, #<struct RFN value=3D2>, #<struct RFN value=3D1>]

I'd rather stick with the other approaches presented or use Array#reverse.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/