summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 05:02:12 +0000
committerktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 05:02:12 +0000
commit3e1360f370a591027b414b582ffdbfe1810f0d12 (patch)
treeddfef331cd8577aa82f13c0c3cdbe597d50d081c /array.c
parent66a96c13f9ce7ba4ada6fffa51a8ab7b9e9c1448 (diff)
* 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
Diffstat (limited to 'array.c')
-rw-r--r--array.c22
1 files changed, 20 insertions, 2 deletions
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) {