mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Integral#step without arg should loop forever as CRuby does.
This commit is contained in:
+8
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user