mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #2655 from tmtm/fix-numeric-step
Fix: Numeric#step infinite loop.
This commit is contained in:
+11
-3
@@ -101,12 +101,20 @@ module Integral
|
||||
# incremented by +step+ (default 1).
|
||||
#
|
||||
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?
|
||||
|
||||
i = if num.kind_of? Float then self.to_f else self end
|
||||
while(i <= num)
|
||||
block.call(i)
|
||||
i += step
|
||||
if step > 0
|
||||
while(i <= num)
|
||||
block.call(i)
|
||||
i += step
|
||||
end
|
||||
else
|
||||
while(i >= num)
|
||||
block.call(i)
|
||||
i += step
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user