Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Integer#div

div(numeric) → integer

Performs integer division; returns the integer result of dividing self by numeric:

  4.div(3)      # => 1
  4.div(-3)      # => -2
  -4.div(3)      # => -2
  -4.div(-3)      # => 1
  4.div(3.0)      # => 1
  4.div(Rational(3, 1))      # => 1

Raises an exception if +numeric+ does not have method +div+.
See also #digits #divmod #denominator #downto also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0