summaryrefslogtreecommitdiffhomepage
path: root/mrblib/numeric.rb
diff options
context:
space:
mode:
Diffstat (limited to 'mrblib/numeric.rb')
-rw-r--r--mrblib/numeric.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb
index 9f65d5633..1d701b1fc 100644
--- a/mrblib/numeric.rb
+++ b/mrblib/numeric.rb
@@ -1,6 +1,6 @@
##
# Integer
-#
+#
# ISO 15.2.8
class Integer
@@ -10,7 +10,6 @@ class Integer
#
# ISO 15.2.8.3.15
def downto(num, &block)
- raise TypeError, "expected Integer" unless num.kind_of? Integer
i = self
while(i >= num)
block.call(i)
@@ -38,7 +37,6 @@ class Integer
#
# ISO 15.2.8.3.27
def upto(num, &block)
- raise TypeError, "expected Integer" unless num.kind_of? Integer
i = self
while(i <= num)
block.call(i)
@@ -46,6 +44,19 @@ class Integer
end
self
end
+
+ ##
+ # Calls the given block from +self+ to +num+
+ # incremented by +step+ (default 1).
+ #
+ def step(num, step=1, &block)
+ i = if num.kind_of? Float then self.to_f else self end
+ while(i <= num)
+ block.call(i)
+ i += step
+ end
+ self
+ end
end
##