ruby-changes:44911
From: nobu <ko1@a...>
Date: Mon, 5 Dec 2016 09:03:49 +0900 (JST)
Subject: [ruby-changes:44911] nobu:r56984 (trunk): random.c: private rand
nobu 2016-12-05 09:03:45 +0900 (Mon, 05 Dec 2016) New Revision: 56984 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56984 Log: random.c: private rand * random.c (rb_random_ulong_limited): do not call private method rand. [ruby-dev:49892] [Misc #13003] Modified files: trunk/random.c trunk/test/ruby/test_array.rb Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 56983) +++ test/ruby/test_array.rb (revision 56984) @@ -2337,6 +2337,13 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L2337 end ary = (0...10000).to_a assert_equal(ary.rotate, ary.shuffle(random: gen_to_int)) + + assert_raise(NoMethodError) { + ary.shuffle(random: Object.new) + } + assert_raise(NoMethodError) { + ary.shuffle!(random: Object.new) + } end def test_sample @@ -2437,6 +2444,10 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L2444 end ary = (0...10000).to_a assert_equal(5000, ary.sample(random: gen_to_int)) + + assert_raise(NoMethodError) { + ary.sample(random: Object.new) + } end def test_cycle Index: random.c =================================================================== --- random.c (revision 56983) +++ random.c (revision 56984) @@ -1018,7 +1018,7 @@ rb_random_ulong_limited(VALUE obj, unsig https://github.com/ruby/ruby/blob/trunk/random.c#L1018 rb_random_t *rnd = try_get_rnd(obj); if (!rnd) { VALUE lim = ulong_to_num_plus_1(limit); - VALUE v = rb_to_int(rb_funcallv(obj, id_rand, 1, &lim)); + VALUE v = rb_to_int(rb_funcallv_public(obj, id_rand, 1, &lim)); unsigned long r = NUM2ULONG(v); if (rb_num_negative_p(v)) { rb_raise(rb_eRangeError, "random number too small %ld", r); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/