diff options
| -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 |
