diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-11-26 08:34:51 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-11-26 08:34:51 +0900 |
| commit | dd1497369700f84f595a7fb006b2f2be400cfae4 (patch) | |
| tree | 08047b32c9a4c3d9677b51a4e06e430b4a4589a8 | |
| parent | 1365151dcb65190b05a97768584f68cb14d584c4 (diff) | |
| parent | bbab89e730eeb74009887b0975f17539e24c4ccd (diff) | |
| download | mruby-dd1497369700f84f595a7fb006b2f2be400cfae4.tar.gz mruby-dd1497369700f84f595a7fb006b2f2be400cfae4.zip | |
Merge pull request #2655 from tmtm/fix-numeric-step
Fix: Numeric#step infinite loop.
| -rw-r--r-- | mrblib/numeric.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index 5be3c90fc..1f44a2c81 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -101,12 +101,20 @@ module Integral # incremented by +step+ (default 1). # def step(num, step=1, &block) + raise ArgumentError, "step can't be 0" if step == 0 return to_enum(:step, num, step) unless block_given? i = if num.kind_of? Float then self.to_f else self end - while(i <= num) - block.call(i) - i += step + if step > 0 + while(i <= num) + block.call(i) + i += step + end + else + while(i >= num) + block.call(i) + i += step + end end self end |
