Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Integer#div

(::Numeric) -> ::Integer
div(numeric) → integer

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

Example
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.3 · 3.2 · 3.1 · 3.0