mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Use the dedicated function to check arity
This commit is contained in:
parent
15d3b7fe6d
commit
56f2fd3bc9
2 changed files with 7 additions and 6 deletions
4
struct.c
4
struct.c
|
@ -742,7 +742,7 @@ rb_struct_initialize_m(int argc, const VALUE *argv, VALUE self)
|
|||
switch (rb_struct_s_keyword_init(klass)) {
|
||||
default:
|
||||
if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) {
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0)", argc);
|
||||
rb_error_arity(argc, 0, 0);
|
||||
}
|
||||
keyword_init = true;
|
||||
break;
|
||||
|
@ -1800,7 +1800,7 @@ rb_data_initialize_m(int argc, const VALUE *argv, VALUE self)
|
|||
return Qnil;
|
||||
}
|
||||
if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) {
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0)", argc);
|
||||
rb_error_arity(argc, 0, 0);
|
||||
}
|
||||
|
||||
if (RHASH_SIZE(argv[0]) < num_members) {
|
||||
|
|
|
@ -428,16 +428,17 @@ rb_vm_pop_frame(rb_execution_context_t *ec)
|
|||
static inline VALUE
|
||||
rb_arity_error_new(int argc, int min, int max)
|
||||
{
|
||||
VALUE err_mess = 0;
|
||||
VALUE err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d", argc, min);
|
||||
if (min == max) {
|
||||
err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d)", argc, min);
|
||||
/* max is not needed */
|
||||
}
|
||||
else if (max == UNLIMITED_ARGUMENTS) {
|
||||
err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d+)", argc, min);
|
||||
rb_str_cat_cstr(err_mess, "+");
|
||||
}
|
||||
else {
|
||||
err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d..%d)", argc, min, max);
|
||||
rb_str_catf(err_mess, "..%d", max);
|
||||
}
|
||||
rb_str_cat_cstr(err_mess, ")");
|
||||
return rb_exc_new3(rb_eArgError, err_mess);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue