diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-01-20 17:58:29 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-01-20 17:58:29 +0900 |
| commit | b23fb45f9ce3cb12b33eecc9cab37adc2890f49f (patch) | |
| tree | 396934a1c12343c9784805c73e1edcb005221799 /mrblib | |
| parent | fe0e45505b0d0fbf627c9a7df0b8df52d0c72321 (diff) | |
| download | mruby-b23fb45f9ce3cb12b33eecc9cab37adc2890f49f.tar.gz mruby-b23fb45f9ce3cb12b33eecc9cab37adc2890f49f.zip | |
Integral#step without arg should loop forever as CRuby does.
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/numeric.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index 17155bfd6..975ad973f 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -100,11 +100,18 @@ module Integral # Calls the given block from +self+ to +num+ # incremented by +step+ (default 1). # - def step(num, step = 1, &block) + def step(num=nil, 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 + if num == nil + while true + block.call(i) + i+=step + end + return self + end if step > 0 while i <= num block.call(i) |
