Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Integer#step added

  • Loading branch information...
commit ef17231bd776b266f1fe3132bde0fb6bbef90257 1 parent 4de0a2a
Yukihiro "Matz" Matsumoto matz authored
Showing with 14 additions and 1 deletion.
  1. +14 −1 mrblib/numeric.rb
15 mrblib/numeric.rb
View
@@ -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
##
Please sign in to comment.
Something went wrong with that request. Please try again.