Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Integer#/
(::BigDecimal) -> ::BigDecimal
(::Integer) -> ::Integer
(::Float) -> ::Float
(::Rational) -> ::Rational
(::Complex) -> ::Complex
self / other → numeric
numeric.c
View on GitHub ↗
VALUE
rb_int_div(VALUE x, VALUE y)
{
if (FIXNUM_P(x)) {
return fix_div(x, y);
}
else if (RB_BIGNUM_TYPE_P(x)) {
return rb_big_div(x, y);
}
return Qnil;
}
Returns the quotient of self and other.
For integer other, returns the largest integer less than or equal to the mathematical quotient:
Example
4 / 3 # => 1 4 / -3 # => -2 -4 / 3 # => -2 -4 / -3 # => 1
For non-integer other, returns a non-integer result:
Example
4 / 3.0 # => 1.3333333333333333 4 / Rational(3, 1) # => (4/3) 4 / Complex(3, 0) # => ((4/3)+0i)