mruby special - module to share methods between Floats and Integers
to make them compatible
Calls the given block once for each Integer from
self
downto num
.
ISO 15.2.8.3.15
# File mrblib/numeric.rb, line 47 def downto(num, &block) return to_enum(:downto, num) unless block i = self.to_i while i >= num block.call(i) i -= 1 end self end
Returns self + 1
ISO 15.2.8.3.19
# File mrblib/numeric.rb, line 62 def next self + 1 end
Calls the given block from self
to num
incremented by step
(default 1).
# File mrblib/numeric.rb, line 103 def step(num=nil, step=1, &block) raise ArgumentError, "step can't be 0" if step == 0 return to_enum(:step, num, step) unless block i = __coerce_step_counter(num, step) if num == self || step.infinite? block.call(i) if step > 0 && i <= (num||i) || step < 0 && i >= (num||-i) elsif num == nil while true block.call(i) i += step end elsif step > 0 while i <= num block.call(i) i += step end else while i >= num block.call(i) i += step end end self end
Calls the given block self
times.
ISO 15.2.8.3.22
# File mrblib/numeric.rb, line 72 def times &block return to_enum :times unless block i = 0 while i < self block.call i i += 1 end self end
Calls the given block once for each Integer from
self
upto num
.
ISO 15.2.8.3.27
# File mrblib/numeric.rb, line 88 def upto(num, &block) return to_enum(:upto, num) unless block i = self.to_i while i <= num block.call(i) i += 1 end self end