Permalink
Browse files

Integer#step added

  • Loading branch information...
1 parent 4de0a2a commit ef17231bd776b266f1fe3132bde0fb6bbef90257 @matz matz committed Sep 15, 2012
Showing with 14 additions and 1 deletion.
  1. +14 −1 mrblib/numeric.rb
View
15 mrblib/numeric.rb
@@ -1,6 +1,6 @@
##
# Integer
-#
+#
# ISO 15.2.8
class Integer
@@ -44,6 +44,19 @@ def upto(num, &block)
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
##

0 comments on commit ef17231

Please sign in to comment.