summaryrefslogtreecommitdiffhomepage
path: root/mrblib
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-01-15 22:27:40 +0900
committerGitHub <[email protected]>2019-01-15 22:27:40 +0900
commitfa34a8b5be7b88c61d0e3bd110452588654471e1 (patch)
treedaaf9e126fd2416e59dd9e57519546320a07c708 /mrblib
parent348442dd5e8fa77823bd4a2e38bbdd9f3a0ac003 (diff)
parentde5da4b7f6615610ee5935754ae76e71870380aa (diff)
downloadmruby-fa34a8b5be7b88c61d0e3bd110452588654471e1.tar.gz
mruby-fa34a8b5be7b88c61d0e3bd110452588654471e1.zip
Merge pull request #4230 from shuujii/fix-coercing-for-step-counter-in-numeric-step
Fix coercing for first step counter in `Numeric#step`
Diffstat (limited to 'mrblib')
-rw-r--r--mrblib/numeric.rb11
1 files changed, 9 insertions, 2 deletions
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