Commit dd149736 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2655 from tmtm/fix-numeric-step

Fix: Numeric#step infinite loop.
parents 1365151d bbab89e7
...@@ -101,12 +101,20 @@ module Integral ...@@ -101,12 +101,20 @@ module Integral
# incremented by +step+ (default 1). # incremented by +step+ (default 1).
# #
def step(num, step=1, &block) 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? return to_enum(:step, num, step) unless block_given?
i = if num.kind_of? Float then self.to_f else self end i = if num.kind_of? Float then self.to_f else self end
while(i <= num) if step > 0
block.call(i) while(i <= num)
i += step block.call(i)
i += step
end
else
while(i >= num)
block.call(i)
i += step
end
end end
self self
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment