Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Integer#/

self / numeric → numeric_result

Performs division; for integer numeric, truncates the result to an integer:

 4 / 3              # => 1
 4 / -3             # => -2
 -4 / 3             # => -2
 -4 / -3            # => 1

For other +numeric+, returns non-integer result:

 4 / 3.0            # => 1.3333333333333333
 4 / Rational(3, 1) # => (4/3)
 4 / Complex(3, 0)  # => ((4/3)+0i)
See also #-@ #< #- #<< also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0