From bbab89e730eeb74009887b0975f17539e24c4ccd Mon Sep 17 00:00:00 2001 From: TOMITA Masahiro Date: Wed, 26 Nov 2014 01:34:07 +0900 Subject: Fix: Numeric#step infinite loop. --- mrblib/numeric.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'mrblib') diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index 5be3c90fc..1f44a2c81 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -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 -- cgit v1.2.3