Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Integer#div
(::Numeric) -> ::Integer
div(numeric) → integer
numeric.c
View on GitHub ↗
VALUE
rb_int_idiv(VALUE x, VALUE y)
{
if (FIXNUM_P(x)) {
return fix_idiv(x, y);
}
else if (RB_BIGNUM_TYPE_P(x)) {
return rb_big_idiv(x, y);
}
return num_div(x, y);
}
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.