Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. 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.2 · 3.1 · 3.0