diff options
-rw-r--r-- | array.c | 17 | ||||
-rw-r--r-- | complex.c | 2 | ||||
-rw-r--r-- | rational.c | 4 | ||||
-rw-r--r-- | re.c | 6 | ||||
-rw-r--r-- | time.c | 2 |
5 files changed, 9 insertions, 22 deletions
@@ -2590,13 +2590,7 @@ rb_ary_rotate(VALUE ary, long cnt) static VALUE rb_ary_rotate_bang(int argc, VALUE *argv, VALUE ary) { - long n = 1; - - switch (argc) { - case 1: n = NUM2LONG(argv[0]); - case 0: break; - default: rb_scan_args(argc, argv, "01", NULL); - } + long n = (rb_check_arity(argc, 0, 1) ? NUM2LONG(argv[0]) : 1); rb_ary_rotate(ary, n); return ary; } @@ -2623,13 +2617,8 @@ rb_ary_rotate_m(int argc, VALUE *argv, VALUE ary) { VALUE rotated; const VALUE *ptr; - long len, cnt = 1; - - switch (argc) { - case 1: cnt = NUM2LONG(argv[0]); - case 0: break; - default: rb_scan_args(argc, argv, "01", NULL); - } + long len; + long cnt = (rb_check_arity(argc, 0, 1) ? NUM2LONG(argv[0]) : 1); len = RARRAY_LEN(ary); rotated = rb_ary_new2(len); @@ -1491,7 +1491,7 @@ nucomp_rationalize(int argc, VALUE *argv, VALUE self) { get_dat1(self); - rb_scan_args(argc, argv, "01", NULL); + rb_check_arity(argc, 0, 1); if (!k_exact_zero_p(dat->imag)) { rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational", diff --git a/rational.c b/rational.c index 47e67f128d..b320ed5501 100644 --- a/rational.c +++ b/rational.c @@ -2121,7 +2121,7 @@ nilclass_to_r(VALUE self) static VALUE nilclass_rationalize(int argc, VALUE *argv, VALUE self) { - rb_scan_args(argc, argv, "01", NULL); + rb_check_arity(argc, 0, 1); return nilclass_to_r(self); } @@ -2150,7 +2150,7 @@ integer_to_r(VALUE self) static VALUE integer_rationalize(int argc, VALUE *argv, VALUE self) { - rb_scan_args(argc, argv, "01", NULL); + rb_check_arity(argc, 0, 1); return integer_to_r(self); } @@ -3960,13 +3960,11 @@ match_setter(VALUE val) static VALUE rb_reg_s_last_match(int argc, VALUE *argv) { - VALUE nth; - - if (argc > 0 && rb_scan_args(argc, argv, "01", &nth) == 1) { + if (rb_check_arity(argc, 0, 1) == 1) { VALUE match = rb_backref_get(); int n; if (NIL_P(match)) return Qnil; - n = match_backref_number(match, nth); + n = match_backref_number(match, argv[0]); return rb_reg_nth_match(n, match); } return match_getter(); @@ -4959,7 +4959,7 @@ time_dump(int argc, VALUE *argv, VALUE time) { VALUE str; - rb_scan_args(argc, argv, "01", 0); + rb_check_arity(argc, 0, 1); str = time_mdump(time); return str; |