diff --git a/struct.c b/struct.c index 3a5dc8b7d4..9793133f80 100644 --- a/struct.c +++ b/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) { diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 98138f5922..03796d2ad1 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -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); }