summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-06 06:52:36 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-06 06:52:36 (GMT)
commit0e303494d099a3d76acbca061ceb3cee5f1dc44b (patch)
tree0538808ceec56ff14d4eed8f04e0a186d6b5110d /random.c
parentc92c82184ccb1169676a0d59ae986ce32a4d5b82 (diff)
random.c: prefer rb_check_arity
* random.c: use rb_check_arity instead of rb_scan_args for simple optional arguments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/random.c b/random.c
index 36dcb54..849c8c5 100644
--- a/random.c
+++ b/random.c
@@ -426,12 +426,12 @@ random_init(int argc, VALUE *argv, VALUE obj)
VALUE vseed;
rb_random_t *rnd = get_rnd(obj);
- if (argc == 0) {
+ if (rb_check_arity(argc, 0, 1) == 0) {
rb_check_frozen(obj);
vseed = random_seed();
}
else {
- rb_scan_args(argc, argv, "01", &vseed);
+ vseed = argv[0];
rb_check_copyable(obj, vseed);
}
rnd->seed = rand_init(&rnd->mt, vseed);
@@ -793,11 +793,11 @@ rb_f_srand(int argc, VALUE *argv, VALUE obj)
VALUE seed, old;
rb_random_t *r = &default_rand;
- if (argc == 0) {
+ if (rb_check_arity(argc, 0, 1) == 0) {
seed = random_seed();
}
else {
- rb_scan_args(argc, argv, "01", &seed);
+ seed = argv[0];
}
old = r->seed;
r->seed = rand_init(&r->mt, seed);
@@ -1407,8 +1407,8 @@ rb_f_rand(int argc, VALUE *argv, VALUE obj)
VALUE v, vmax, r;
rb_random_t *rnd = rand_start(&default_rand);
- if (argc == 0) goto zero_arg;
- rb_scan_args(argc, argv, "01", &vmax);
+ if (rb_check_arity(argc, 0, 1) == 0) goto zero_arg;
+ vmax = argv[0];
if (NIL_P(vmax)) goto zero_arg;
if ((v = rand_range(Qnil, rnd, vmax)) != Qfalse) {
return v;