From: Stefano Crocco Date: 2011-02-01T18:21:45+09:00 Subject: Re: Decreasing range? On Tuesday 01 February 2011 17:43:44 Stefano Grioni wrote: > Thank you both, I feel ashamed that I didn't think about "downto" .. > Concerning my more general question, do you have any clue about why > decreasing ranges behave the way they do? > > Thank you Range#each calls the #succ method of the starting element to get the new one and goes on like this until the next element is greater than the last. If Range#each were written in ruby, I think it could be something like this (it's just a guess, I didn't look at the actual code): class Range def each current = @start while (current <=> @end) < 1 yield current current = current.succ end end end In your case @start would be 4, while @end would be 1. Since 4 is greater than 1, the block is never called. Stefano