Skip to content
Permalink
Browse files
Integral#step without arg should loop forever as CRuby does.
  • Loading branch information
matz committed Jan 20, 2017
1 parent fe0e455 commit b23fb45f9ce3cb12b33eecc9cab37adc2890f49f
Showing 1 changed file with 8 additions and 1 deletion.
@@ -100,11 +100,18 @@ def upto(num, &block)
# 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)

0 comments on commit b23fb45

Please sign in to comment.