From: Adam Shelly Date: 2008-07-03T02:13:41+09:00 Subject: Re: Ranges and Enumerable problems On 7/2/08, Glen Holcomb wrote: > That is interesting. I wonder why it doesn't work as you would expect. The > range object seems to be correct (at least through limited include? testing) > however it returns incomplete info whenever you use an Enumerable method or > a method that appears to use an Enumerable method. > It's not Enumerable, it's the Range class's #each method. In general, Ranges use the <=> operator to test against the first and last element to determine inclusion, but they use #succ to generate the next element for #each. Some odd behavior arises because (s<=>s.succ) != -1 for all s. I thought that was the whole issue, but it turns out '10' <=> '~' is -1. It turns out the Range class has special code to deal with Strings - it also checks that s.succ.length < end.length. Without that, your example range would enumerate forever. There has been discussion off and on about changing Range to use some new alternate method to #succ which would guarantee 'sane' behavoir, but nothing has ever come of it. -Adam