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

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

instance method Rational#*

self * other -> Rational | Float[permalink][rdoc]

積を計算します。

[PARAM] other:
自身に掛ける数

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

例:

Rational(3, 4) * 2              # => Rational(3, 2)
Rational(3, 4) * 4              # => Rational(3, 1)
Rational(3, 4) * 0.5            # => 0.375
Rational(3, 4) * Rational(1, 2) # => Rational(3, 8)

other に 0 を指定した場合も Rational を返します。

Rational(3, 4) * 0              # => Rational(0, 1)