Prefer rb_check_arity when 0 or 1 arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b0ec083a20
commit
4b85e88174
17
array.c
17
array.c
@ -2590,13 +2590,7 @@ rb_ary_rotate(VALUE ary, long cnt)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_ary_rotate_bang(int argc, VALUE *argv, VALUE ary)
|
rb_ary_rotate_bang(int argc, VALUE *argv, VALUE ary)
|
||||||
{
|
{
|
||||||
long n = 1;
|
long n = (rb_check_arity(argc, 0, 1) ? NUM2LONG(argv[0]) : 1);
|
||||||
|
|
||||||
switch (argc) {
|
|
||||||
case 1: n = NUM2LONG(argv[0]);
|
|
||||||
case 0: break;
|
|
||||||
default: rb_scan_args(argc, argv, "01", NULL);
|
|
||||||
}
|
|
||||||
rb_ary_rotate(ary, n);
|
rb_ary_rotate(ary, n);
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
@ -2623,13 +2617,8 @@ rb_ary_rotate_m(int argc, VALUE *argv, VALUE ary)
|
|||||||
{
|
{
|
||||||
VALUE rotated;
|
VALUE rotated;
|
||||||
const VALUE *ptr;
|
const VALUE *ptr;
|
||||||
long len, cnt = 1;
|
long len;
|
||||||
|
long cnt = (rb_check_arity(argc, 0, 1) ? NUM2LONG(argv[0]) : 1);
|
||||||
switch (argc) {
|
|
||||||
case 1: cnt = NUM2LONG(argv[0]);
|
|
||||||
case 0: break;
|
|
||||||
default: rb_scan_args(argc, argv, "01", NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
len = RARRAY_LEN(ary);
|
len = RARRAY_LEN(ary);
|
||||||
rotated = rb_ary_new2(len);
|
rotated = rb_ary_new2(len);
|
||||||
|
@ -1491,7 +1491,7 @@ nucomp_rationalize(int argc, VALUE *argv, VALUE self)
|
|||||||
{
|
{
|
||||||
get_dat1(self);
|
get_dat1(self);
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01", NULL);
|
rb_check_arity(argc, 0, 1);
|
||||||
|
|
||||||
if (!k_exact_zero_p(dat->imag)) {
|
if (!k_exact_zero_p(dat->imag)) {
|
||||||
rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
|
rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
|
||||||
|
@ -2121,7 +2121,7 @@ nilclass_to_r(VALUE self)
|
|||||||
static VALUE
|
static VALUE
|
||||||
nilclass_rationalize(int argc, VALUE *argv, VALUE self)
|
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);
|
return nilclass_to_r(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2150,7 +2150,7 @@ integer_to_r(VALUE self)
|
|||||||
static VALUE
|
static VALUE
|
||||||
integer_rationalize(int argc, VALUE *argv, VALUE self)
|
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);
|
return integer_to_r(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
re.c
6
re.c
@ -3960,13 +3960,11 @@ match_setter(VALUE val)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_reg_s_last_match(int argc, VALUE *argv)
|
rb_reg_s_last_match(int argc, VALUE *argv)
|
||||||
{
|
{
|
||||||
VALUE nth;
|
if (rb_check_arity(argc, 0, 1) == 1) {
|
||||||
|
|
||||||
if (argc > 0 && rb_scan_args(argc, argv, "01", &nth) == 1) {
|
|
||||||
VALUE match = rb_backref_get();
|
VALUE match = rb_backref_get();
|
||||||
int n;
|
int n;
|
||||||
if (NIL_P(match)) return Qnil;
|
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 rb_reg_nth_match(n, match);
|
||||||
}
|
}
|
||||||
return match_getter();
|
return match_getter();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user