In Files

  • mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb
  • mrblib/numeric.rb
toggle debugging

Integral

Integral

mruby special - module to share methods between Floats and Integers

to make them compatible

Public Instance Methods

div(other) click to toggle source
 
               # File mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb, line 2
def div(other)
  self.divmod(other)[0]
end
            
downto(num, &block) click to toggle source

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_given?

  i = self.to_i
  while i >= num
    block.call(i)
    i -= 1
  end
  self
end
            
next() click to toggle source

Returns self + 1

ISO 15.2.8.3.19

 
               # File mrblib/numeric.rb, line 62
def next
  self + 1
end
            
Also aliased as: succ
nonzero?() click to toggle source
 
               # File mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb, line 10
def nonzero?
  if self == 0
    nil
  else
    self
  end
end
            
step(num, step = 1, &block) click to toggle source

Calls the given block from self to num incremented by step (default 1).

 
               # File mrblib/numeric.rb, line 103
def step(num, step = 1, &block)
  raise ArgumentError, "step can't be 0" if step == 0
  return to_enum(:step, num, step) unless block_given?

  i = if num.kind_of? Float then self.to_f else self end
  if step > 0
    while i <= num
      block.call(i)
      i += step
    end
  else
    while i >= num
      block.call(i)
      i += step
    end
  end
  self
end
            
succ() click to toggle source

ISO 15.2.8.3.21

Alias for: next
times(&block) click to toggle source

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_given?

  i = 0
  while i < self
    block.call i
    i += 1
  end
  self
end
            
upto(num, &block) click to toggle source

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_given?

  i = self.to_i
  while i <= num
    block.call(i)
    i += 1
  end
  self
end
            
zero?() click to toggle source
 
               # File mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb, line 6
def zero?
  self == 0
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.