From: Tim Hunter Date: 2006-03-12T08:53:44+09:00 Subject: Re: unexpected behavior of range.each (Newbie extreme) Joe Percival wrote: > with r=(5..9), r.each{|num| print num,"\n"} behaves as expected. > > However if i set r=(9..5) the same method does not behave as though it > were taking "each" element of the range. It just terminates. Not only > that but r.include?(7) is false??? > > Is this a bug or was it done on purpose for some reason? Are range > specifications only allowed to be "low to high" if so, why? Also if > so, then why no error message and why does r = (9..5)? > > Thanks in advance! > joe > It was done on purpose. Ranges want to be able to iterate from beginning to end using the .succ method on the objects that the range is constructed from. That's not possible for (9..5). Also, the definition for .include? is range.start <= val <= range.end. Not true for (9..5).