ruby-changes:35825
From: akr <ko1@a...>
Date: Tue, 14 Oct 2014 01:30:15 +0900 (JST)
Subject: [ruby-changes:35825] akr:r47907 (trunk): * enum.c (nmin_run): max(n) and max_by(n) returns an array in
akr 2014-10-14 01:30:07 +0900 (Tue, 14 Oct 2014) New Revision: 47907 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47907 Log: * enum.c (nmin_run): max(n) and max_by(n) returns an array in descending order. [ruby-core:65452] Suggested by David Grayson. Modified files: trunk/ChangeLog trunk/enum.c trunk/test/ruby/test_enum.rb trunk/test/ruby/test_range.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 47906) +++ ChangeLog (revision 47907) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Oct 14 01:27:54 2014 Tanaka Akira <akr@f...> + + * enum.c (nmin_run): max(n) and max_by(n) returns an array in + descending order. + [ruby-core:65452] Suggested by David Grayson. + Mon Oct 13 20:44:49 2014 Nobuyoshi Nakada <nobu@r...> * common.mk (update-gems): chdir to the target directory and then Index: enum.c =================================================================== --- enum.c (revision 47906) +++ enum.c (revision 47907) @@ -1284,6 +1284,9 @@ nmin_run(VALUE obj, VALUE num, int by, i https://github.com/ruby/ruby/blob/trunk/enum.c#L1284 ruby_qsort(RARRAY_PTR(result), RARRAY_LEN(result), sizeof(VALUE), data.cmpfunc, (void *)&data); } + if (rev) { + rb_ary_reverse(result); + } *((VALUE *)&RBASIC(result)->klass) = rb_cArray; return result; Index: test/ruby/test_range.rb =================================================================== --- test/ruby/test_range.rb (revision 47906) +++ test/ruby/test_range.rb (revision 47907) @@ -81,8 +81,8 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L81 assert_equal(0, (0..0).max) assert_equal(nil, (0...0).max) - assert_equal([8,9,10], (0..10).max(3)) - assert_equal([7,8,9], (0...10).max(3)) + assert_equal([10,9,8], (0..10).max(3)) + assert_equal([9,8,7], (0...10).max(3)) end def test_initialize_twice Index: test/ruby/test_enum.rb =================================================================== --- test/ruby/test_enum.rb (revision 47906) +++ test/ruby/test_enum.rb (revision 47907) @@ -245,8 +245,8 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L245 assert_equal("horse", ary.max) assert_equal("albatross", ary.max {|a,b| a.length <=> b.length }) assert_equal(1, [3,2,1].max{|a,b| b <=> a }) - assert_equal(%w[dog horse], ary.max(2)) - assert_equal(%w[horse albatross], + assert_equal(%w[horse dog], ary.max(2)) + assert_equal(%w[albatross horse], ary.max(2) {|a,b| a.length <=> b.length }) end @@ -278,7 +278,7 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L278 a = %w(albatross dog horse) assert_equal("albatross", a.max_by {|x| x.length }) assert_equal(1, [2,3,1].max_by {|x| -x }) - assert_equal(%w[horse albatross], a.max_by(2) {|x| x.length }) + assert_equal(%w[albatross horse], a.max_by(2) {|x| x.length }) end def test_minmax_by -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/