From 3e1360f370a591027b414b582ffdbfe1810f0d12 Mon Sep 17 00:00:00 2001 From: ktsj Date: Sun, 8 Dec 2013 05:02:12 +0000 Subject: * array.c (rb_ary_shuffle_bang, rb_ary_sample): check unknown keywords. * test/ruby/test_array.rb (test_shuffle, test_sample): tests for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'array.c') diff --git a/array.c b/array.c index bc0cfa82b9..12469090be 100644 --- a/array.c +++ b/array.c @@ -4431,9 +4431,18 @@ rb_ary_shuffle_bang(int argc, VALUE *argv, VALUE ary) { VALUE opts, randgen = rb_cRandom; long i, len; + static ID keyword_ids[1]; + + if (!keyword_ids[0]) { + keyword_ids[0] = rb_intern("random"); + } if (OPTHASH_GIVEN_P(opts)) { - randgen = rb_hash_lookup2(opts, sym_random, randgen); + VALUE random; + rb_get_kwargs(opts, keyword_ids, 0, 1, &random); + if (random != Qundef) { + randgen = random; + } } rb_check_arity(argc, 0, 0); rb_ary_modify(ary); @@ -4509,9 +4518,18 @@ rb_ary_sample(int argc, VALUE *argv, VALUE ary) VALUE opts, randgen = rb_cRandom; long n, len, i, j, k, idx[10]; long rnds[numberof(idx)]; + static ID keyword_ids[1]; + + if (!keyword_ids[0]) { + keyword_ids[0] = rb_intern("random"); + } if (OPTHASH_GIVEN_P(opts)) { - randgen = rb_hash_lookup2(opts, sym_random, randgen); + VALUE random; + rb_get_kwargs(opts, keyword_ids, 0, 1, &random); + if (random != Qundef) { + randgen = random; + } } len = RARRAY_LEN(ary); if (argc == 0) { -- cgit v1.2.3