mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Integer#step added
This commit is contained in:
+14
-1
@@ -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
|
||||
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user