From: Yukihiro Matsumoto Date: 2009-08-17T07:20:08+09:00 Subject: Re: Bizarre Range behavior Hi, In message "Re: Bizarre Range behavior" on Thu, 6 Aug 2009 01:44:56 +0900, James Coglan writes: |Quite. I think consistency is important, and this is currently broken in |1.9: | |$ irb1.8 |>> ('!'..']').to_a |=> ["!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", |"/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] |>> '9'.succ |=> "10" | |$ irb1.9 |>> ('!'..']').to_a |=> ["!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", |"/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", |">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", |"M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", |"\\", "]"] |>> '9'.succ |=> "10" |There is obviously room for debate over the above examples: the 1.9 one |could be viewed as more complete even though it doesn't apply #succ |consistently. A lot of these odd examples are edge cases that are unlikely |to come up in production code, but personally I find the rules used by 1.8 |easier to understand. If I define my own class, Range will use its #succ and |#<=> methods to carry out its logic and I expect the same for built-in |classes. I admit 1.8 behavior in above example is simpler to implement, but 1.9 behavior follows our (or more precisely "my") unwritten expectation of character iteration. Simple #upto (a la 1.8) can act as weirdly, since #succ don't know about the edge values. I want to make #upto work smart. I know it's magical, but #upto (and Range#each) already contains magic. So I consider the weird (even unexpected for OP) behavior is a result from less magic. I am not sure the new behavior should be back-ported to 1.8 or not. matz.