Commit ef17231b authored by Yukihiro Matsumoto's avatar Yukihiro Matsumoto

Integer#step added

parent 4de0a2af
## ##
# Integer # Integer
# #
# ISO 15.2.8 # ISO 15.2.8
class Integer class Integer
...@@ -44,6 +44,19 @@ class Integer ...@@ -44,6 +44,19 @@ class Integer
end end
self self
end 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 end
## ##
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment