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

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

instance method Rational#+

self + other -> Rational | Float[permalink][rdoc][edit]

和を計算します。

[PARAM] other:
self に足す数

otherFloat を指定した場合は、計算結果を Float で返します。

r = Rational(3, 4)
p r + Rational(1, 2)   # => (5/4)
p r + 1                # => (7/4)
p r + 0.5              # => 1.25