Integer#step added

This commit is contained in:
Yukihiro Matsumoto
2012-09-15 15:04:51 +09:00
parent 4de0a2afbf
commit ef17231bd7
+14 -1
View File
@@ -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
##