https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112009-03-27T07:36:58ZRuby Issue Tracking SystemRuby master - Bug #1317: Creating a range with stringshttps://bugs.ruby-lang.org/issues/1317?journal_id=36462009-03-27T07:36:58Zmike (Michael Selig)michael_selig@fs.com.au
<ul></ul><p>=begin<br>
This is a (possibly confusing) consequence of the behaviour of String#next.<br>
For most sortable objects, the following is true:</p>
<p>obj.next > obj</p>
<p>but not for strings. For example:</p>
<p>"9".next => "10"<br>
but<br>
"10" > "9" => false</p>
<p>So if you think of a range as a potential "for" loop in a C-style syntax it would be:</p>
<p>for (obj = start; obj < end; obj = next(obj)) ....</p>
<p>then you will see that the loop will stop immediately when start is "2" and end is "10".</p>
<p>Obviously the behaviour of string comparison can't be changed.</p>
<p>Cheers<br>
Mike.<br>
=end</p> Ruby master - Bug #1317: Creating a range with stringshttps://bugs.ruby-lang.org/issues/1317?journal_id=36472009-03-27T07:59:32Zjredville (Jim Deville)jdeville@microsoft.com
<ul></ul><p>=begin</p>
<blockquote>
<p>-----Original Message-----<br>
From: Michael Selig [<a href="mailto:redmine@ruby-lang.org" class="email">mailto:redmine@ruby-lang.org</a>]<br>
Sent: Thursday, March 26, 2009 3:34 PM<br>
To: <a href="mailto:ruby-core@ruby-lang.org" class="email">ruby-core@ruby-lang.org</a><br>
Subject: <a href="https://blade.ruby-lang.org/ruby-core/23027">[ruby-core:23027]</a> [Bug <a class="issue tracker-1 status-6 priority-4 priority-default closed" title="Bug: Creating a range with strings (Rejected)" href="https://bugs.ruby-lang.org/issues/1317">#1317</a>] Creating a range with strings</p>
<p>Issue <a class="issue tracker-1 status-6 priority-4 priority-default closed" title="Bug: Creating a range with strings (Rejected)" href="https://bugs.ruby-lang.org/issues/1317">#1317</a> has been updated by Michael Selig.</p>
<p>This is a (possibly confusing) consequence of the behaviour of<br>
String#next.<br>
For most sortable objects, the following is true:</p>
<p>obj.next > obj</p>
<p>but not for strings. For example:</p>
<p>"9".next => "10"<br>
but<br>
"10" > "9" => false</p>
</blockquote>
<p>Why doesn't Ruby have a collation concept to allow this to be changed?</p>
<p>JD</p>
<p>=end</p> Ruby master - Bug #1317: Creating a range with stringshttps://bugs.ruby-lang.org/issues/1317?journal_id=36482009-03-27T10:18:23Zphasis68 (Heesob Park)phasis@gmail.com
<ul></ul><p>=begin<br>
2009/3/27 Michael Selig <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-6 priority-4 priority-default closed" title="Bug: Creating a range with strings (Rejected)" href="https://bugs.ruby-lang.org/issues/1317">#1317</a> has been updated by Michael Selig.</p>
<p>This is a (possibly confusing) consequence of the behaviour of String#next.<br>
For most sortable objects, the following is true:</p>
<p>obj.next > obj</p>
<p>but not for strings. For example:</p>
<p>"9".next => "10"<br>
but<br>
"10" > "9" => false</p>
<p>So if you think of a range as a potential "for" loop in a C-style syntax it would be:</p>
<p>for (obj = start; obj < end; obj = next(obj)) ....</p>
<p>then you will see that the loop will stop immediately when start is "2" and end is "10".</p>
<p>Obviously the behaviour of string comparison can't be changed.</p>
</blockquote>
<p>I'm not sure the range use String#next.</p>
<p>On ruby 1.9.1 and 1.8.6, "Z".next is "AA".</p>
<p>But the result is different from each other.</p>
<p>[sidns@ns httpd]$ ruby -v -e "p(('A'..'z').to_a)"<br>
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]<br>
["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",<br>
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]</p>
<p>[siweb@localhost ~]$ ruby -v -e "p(('A'..'z').to_a)"<br>
ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]<br>
["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",<br>
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\",<br>
"]", "^", "_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",<br>
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",<br>
"y", "z"]</p>
<p>Regards,</p>
<p>Park Heesob</p>
<p>=end</p> Ruby master - Bug #1317: Creating a range with stringshttps://bugs.ruby-lang.org/issues/1317?journal_id=48212009-07-16T18:10:51Zyugui (Yuki Sonoda)yugui@yugui.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>=begin</p>
<p>=end</p>