diff options
| author | KOBAYASHI Shuji <[email protected]> | 2019-01-15 21:41:54 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2019-01-15 21:41:54 +0900 |
| commit | de5da4b7f6615610ee5935754ae76e71870380aa (patch) | |
| tree | daaf9e126fd2416e59dd9e57519546320a07c708 /mrblib | |
| parent | 348442dd5e8fa77823bd4a2e38bbdd9f3a0ac003 (diff) | |
| download | mruby-de5da4b7f6615610ee5935754ae76e71870380aa.tar.gz mruby-de5da4b7f6615610ee5935754ae76e71870380aa.zip | |
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]
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/numeric.rb | 11 |
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 |
