Skip to content

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

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)
See also #-@ #< #- #<< also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0