Ranges


(Peter Hickman) #1

Is there a particular reason why

(10…1).each {|n| puts n}

doesn’t do the reverse of

(1…10).each {|n| puts n}

I know I can get round it with

10.downto(1) {…}

but I would like to use a consistent syntax in my programs


(ts) #2

(10..1).each {|n| puts n}

Range#each use #succ

To make it work like you want, I think that it must use the opposite which
can be difficult to define in some case (for example String)

Guy Decoux