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

instance method Rational#*

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

積を計算します。

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

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


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