[#74190] [Ruby trunk Feature#12134] Comparison between `true` and `false` — duerst@...
Issue #12134 has been updated by Martin D端rst.
3 messages
2016/03/07
[#74269] Type systems for Ruby — Rob Blanco <ml@...>
Dear ruby-core,
5 messages
2016/03/10
[#74395] [Ruby trunk Feature#12142] Hash tables with open addressing — shyouhei@...
Issue #12142 has been updated by Shyouhei Urabe.
3 messages
2016/03/17
[ruby-core:74605] [Ruby trunk Bug#12221][Rejected] Enumerable#sort_by method doesn't work properly when the array has more than 6 elements and you pass nil to the block
From:
duerst@...
Date:
2016-03-27 09:42:36 UTC
List:
ruby-core #74605
Issue #12221 has been updated by Martin D端rst.
Status changed from Open to Rejected
Tsuyoshi Sawada wrote:
> What is wrong with it?
To expand on this, you tell Ruby that all the values in the array should be 'valued' at nil. Therefore, they are equal, and any order will be correct. You can exchange nil with any other constant, and get the same result. It looks somewhat surprising in your examples, but the reason that the values get shuffled around is that in general (i.e. when most values are not equal), it leads to an efficient algorithm.
To get what you want, juts use the original array :-). Ruby's sort methods are not stable (i.e., they don't keep the original order if two elements compare as equal). Just do a search for Ruby stable sorting, and you will find a lot of useful explanations.
----------------------------------------
Bug #12221: Enumerable#sort_by method doesn't work properly when the array has more than 6 elements and you pass nil to the block
https://bugs.ruby-lang.org/issues/12221#change-57732
* Author: Lucas Caton
* Status: Rejected
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
~~~
%w(1 2).sort_by { |i| nil }
# => ["1", "2"]
# ...
%w(1 2 3 4 5 6).sort_by { |i| nil }
# => ["1", "2", "3", "4", "5", "6"]
~~~
So far, so good...
But look what happens when you have 7 or more elements:
~~~
%w(1 2 3 4 5 6 7).sort_by { |i| nil }
# => ["4", "2", "3", "1", "5", "6", "7"]
%w(1 2 3 4 5 6 7 8).sort_by { |i| nil }
# => ["8", "2", "3", "4", "5", "6", "7", "1"]
%w(1 2 3 4 5 6 7 8 9).sort_by { |i| nil }
# => ["9", "2", "3", "4", "5", "6", "7", "8", "1"]
%w(1 2 3 4 5 6 7 8 9 10).sort_by { |i| nil }
# => ["10", "2", "3", "4", "5", "6", "7", "8", "9", "1"]
~~~
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>