summaryrefslogtreecommitdiffhomepage
path: root/mrblib/numeric.rb
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-09-15 15:04:51 +0900
committerYukihiro Matsumoto <[email protected]>2012-09-15 15:04:51 +0900
commitef17231bd776b266f1fe3132bde0fb6bbef90257 (patch)
tree7150e49a2e6dd54d8acea0de30b8d5c3daa2dc95 /mrblib/numeric.rb
parent4de0a2afbfc851047e20cef28e96d9e982f88096 (diff)
downloadmruby-ef17231bd776b266f1fe3132bde0fb6bbef90257.tar.gz
mruby-ef17231bd776b266f1fe3132bde0fb6bbef90257.zip
Integer#step added
Diffstat (limited to 'mrblib/numeric.rb')
-rw-r--r--mrblib/numeric.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb
index c1b6b39c0..1d701b1fc 100644
--- a/mrblib/numeric.rb
+++ b/mrblib/numeric.rb
@@ -1,6 +1,6 @@
##
# Integer
-#
+#
# ISO 15.2.8
class Integer
@@ -44,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
##