このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ

Ruby 3.0 リファレンスマニュアル

instance method Integer#/

self / other -> Numeric[permalink][rdoc][edit]

selfother で割った値(=商)を返します。other のクラスによって除算の種類が異なります。

otherInteger の場合、整商(整数の商)を Integer で返します。普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。

otherFloatRationalComplex の場合、普通の商を other と同じクラスのインスタンスで返します。

Integer オブジェクトを左項とする算術演算子 / はこのメソッドの呼び出しになります。

[PARAM] other:
self に対する除数
# 整商を返す例
p 7 / 2 # => 3
p 7 / -2 # => -4

# 普通の商を返す例
p 7 / 2.0 # => 3.5
p 7 / 2r # => (7/2)
p 7 / (2+0i) # => ((7/2)+0i)

begin
  2 / 0
rescue => e
  e # => #<ZeroDivisionError: divided by 0>
end

[SEE_ALSO] Integer#div, Integer#fdiv, Numeric#quo