From: Heesob Park Date: 2009-03-27T10:14:52+09:00 Subject: [ruby-core:23030] Re: [Bug #1317] Creating a range with strings 2009/3/27 Michael Selig : > Issue #1317 has been updated by Michael Selig. > > > This is a (possibly confusing) consequence of the behaviour of String#next. > For most sortable objects, the following is true: > > obj.next > obj > > but not for strings. For example: > > "9".next => "10" > but > "10" > "9" => false > > So if you think of a range as a potential "for" loop in a C-style syntax it would be: > > for (obj = start; obj < end; obj = next(obj)) .... > > then you will see that the loop will stop immediately when start is "2" and end is "10". > > Obviously the behaviour of string comparison can't be changed. > I'm not sure the range use String#next. On ruby 1.9.1 and 1.8.6, "Z".next is "AA". But the result is different from each other. [sidns@ns httpd]$ ruby -v -e "p(('A'..'z').to_a)" ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux] ["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"] [siweb@localhost ~]$ ruby -v -e "p(('A'..'z').to_a)" ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux] ["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", "[", "\\", "]", "^", "_", "`", "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"] Regards, Park Heesob