From de5da4b7f6615610ee5935754ae76e71870380aa Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Tue, 15 Jan 2019 21:41:54 +0900 Subject: Fix coercing for first step counter in `Numeric#step` Before: a=[]; 7.step(4, -3.0) { |c| a << c }; p a #=> [7, 4.0] After / Ruby: a=[]; 7.step(4, -3.0) { |c| a << c }; p a #=> [7.0, 4.0] --- mrblib/numeric.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'mrblib') diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index a2eb9c450..dfdaf9da8 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -104,11 +104,18 @@ module Integral raise ArgumentError, "step can't be 0" if step == 0 return to_enum(:step, num, step) unless block - i = if Object.const_defined?(:Float) && num.kind_of?(Float) then self.to_f else self end + i = self + if Object.const_defined?(:Float) && + (kind_of?(Float) || num.kind_of?(Float) || step.kind_of?(Float)) + i = i.to_f + num = num.to_f unless num == nil + step = step.to_f + end + if num == nil while true block.call(i) - i+=step + i += step end return self end -- cgit v1.2.3