Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > rationalライブラリ > Rationalクラス > *

instance method Rational#*

self * other -> Rational | Float

積を計算します。

[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)
class Rational