diff options
| author | TOMITA Masahiro <[email protected]> | 2014-11-26 01:34:07 +0900 |
|---|---|---|
| committer | TOMITA Masahiro <[email protected]> | 2014-11-26 01:34:07 +0900 |
| commit | bbab89e730eeb74009887b0975f17539e24c4ccd (patch) | |
| tree | 08047b32c9a4c3d9677b51a4e06e430b4a4589a8 /mrblib/numeric.rb | |
| parent | 1365151dcb65190b05a97768584f68cb14d584c4 (diff) | |
| download | mruby-bbab89e730eeb74009887b0975f17539e24c4ccd.tar.gz mruby-bbab89e730eeb74009887b0975f17539e24c4ccd.zip | |
Fix: Numeric#step infinite loop.
Diffstat (limited to 'mrblib/numeric.rb')
| -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 |
