diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index a047f019c..0d8dff8a0 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -104,7 +104,7 @@ class Integer raise ArgumentError, "step can't be 0" if step == 0 return to_enum(:step, num, step) unless block - i = __coerce_step_counter(num, step) + i = __coerce_step_counter(step) if num == self || step.infinite? block.call(i) if step > 0 && i <= (num||i) || step < 0 && i >= (num||-i) elsif num == nil diff --git a/src/numeric.c b/src/numeric.c index 59e0c59ee..50f27e913 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -266,17 +266,13 @@ int_quo(mrb_state *mrb, mrb_value x) static mrb_value coerce_step_counter(mrb_state *mrb, mrb_value self) { - mrb_value num, step; - - mrb_get_args(mrb, "oo", &num, &step); - -#ifndef MRB_NO_FLOAT mrb->c->ci->mid = 0; - if (mrb_float_p(num) || mrb_float_p(step)) { + mrb_value step = mrb_get_arg1(mrb); +#ifndef MRB_NO_FLOAT + if (mrb_float_p(step)) { return mrb_ensure_float_type(mrb, self); } #endif - return self; } @@ -2169,7 +2165,7 @@ mrb_init_numeric(mrb_state *mrb) mrb_define_method_id(mrb, integer, MRB_SYM(to_s), int_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */ mrb_define_method_id(mrb, integer, MRB_SYM(inspect), int_to_s, MRB_ARGS_OPT(1)); mrb_define_method_id(mrb, integer, MRB_SYM(divmod), int_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30(x) */ - mrb_define_method_id(mrb, integer, MRB_SYM(__coerce_step_counter), coerce_step_counter, MRB_ARGS_REQ(2)); + mrb_define_method_id(mrb, integer, MRB_SYM(__coerce_step_counter), coerce_step_counter, MRB_ARGS_REQ(1)); /* Fixnum Class for compatibility */ mrb_define_const_id(mrb, mrb->object_class, MRB_SYM(Fixnum), mrb_obj_value(integer)); diff --git a/test/t/numeric.rb b/test/t/numeric.rb index 8baf6c883..5c256ea90 100644 --- a/test/t/numeric.rb +++ b/test/t/numeric.rb @@ -66,7 +66,7 @@ assert('Numeric#step') do skip unless Object.const_defined?(:Float) inf = Float::INFINITY assert_raise(ArgumentError) { 1.step(2, 0.0) { break } } - assert_step([2.0, 3.0, 4.0], 2, [4.0]) + assert_step([2, 3, 4], 2, [4.0]) assert_step([7.0, 4.0, 1.0, -2.0], 7, [-4, -3.0]) assert_step([2.0, 3.0, 4.0], 2.0, [4]) assert_step([10.0, 11.0, 12.0, 13.0], 10.0, [], inf: true)