From: Daniel Schierbeck Date: 2007-02-20T02:45:27+09:00 Subject: Re: For loops don't count down On Mon, 2007-02-19 at 22:38 +0900, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: For loops don't count down" > on Mon, 19 Feb 2007 22:27:02 +0900, SonOfLilit writes: > > |Numeric#step counts down: > | > |5.step(-1) do |i| > | #stuff > |end > > 5.downto(1) do |i| > end Is there a necessity for a range such as 5..0 to be empty? It would otherwise be easy to make iteration work for such cases. This is a simplified solution that doesn't take into account #exclude_end? class Range def each obj = first if first <= last while obj <= last yield obj obj = obj.succ end else while first >= last yield obj obj = obj.pre end end end end This would of course require that the objects in such a "reverse" range respond to #pre, or whatever other name would be more suitable. I'm basically asking if there is a reason why we shouldn't expand the functionality of Range#each, other than backwards compatibility (not that that isn't a big consideration.) Cheers, Daniel Schierbeck