Skip to content

Commit 56f2fd3

Browse files
committed
Use the dedicated function to check arity
1 parent 15d3b7f commit 56f2fd3

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

struct.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ rb_struct_initialize_m(int argc, const VALUE *argv, VALUE self)
742742
switch (rb_struct_s_keyword_init(klass)) {
743743
default:
744744
if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) {
745-
rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0)", argc);
745+
rb_error_arity(argc, 0, 0);
746746
}
747747
keyword_init = true;
748748
break;
@@ -1800,7 +1800,7 @@ rb_data_initialize_m(int argc, const VALUE *argv, VALUE self)
18001800
return Qnil;
18011801
}
18021802
if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) {
1803-
rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0)", argc);
1803+
rb_error_arity(argc, 0, 0);
18041804
}
18051805

18061806
if (RHASH_SIZE(argv[0]) < num_members) {

vm_insnhelper.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,16 +428,17 @@ rb_vm_pop_frame(rb_execution_context_t *ec)
428428
static inline VALUE
429429
rb_arity_error_new(int argc, int min, int max)
430430
{
431-
VALUE err_mess = 0;
431+
VALUE err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d", argc, min);
432432
if (min == max) {
433-
err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d)", argc, min);
433+
/* max is not needed */
434434
}
435435
else if (max == UNLIMITED_ARGUMENTS) {
436-
err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d+)", argc, min);
436+
rb_str_cat_cstr(err_mess, "+");
437437
}
438438
else {
439-
err_mess = rb_sprintf("wrong number of arguments (given %d, expected %d..%d)", argc, min, max);
439+
rb_str_catf(err_mess, "..%d", max);
440440
}
441+
rb_str_cat_cstr(err_mess, ")");
441442
return rb_exc_new3(rb_eArgError, err_mess);
442443
}
443444

0 commit comments

Comments
 (0)