Skip to content

Commit b23fb45

Browse files
committed
Integral#step without arg should loop forever as CRuby does.
1 parent fe0e455 commit b23fb45

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mrblib/numeric.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,18 @@ def upto(num, &block)
100100
# Calls the given block from +self+ to +num+
101101
# incremented by +step+ (default 1).
102102
#
103-
def step(num, step = 1, &block)
103+
def step(num=nil, step=1, &block)
104104
raise ArgumentError, "step can't be 0" if step == 0
105105
return to_enum(:step, num, step) unless block_given?
106106

107107
i = if num.kind_of? Float then self.to_f else self end
108+
if num == nil
109+
while true
110+
block.call(i)
111+
i+=step
112+
end
113+
return self
114+
end
108115
if step > 0
109116
while i <= num
110117
block.call(i)

0 commit comments

Comments
 (0)