Ruby 1.9.2 Reference Manual > All Libraries > Builtin Library > class Rational > coerce

instance method Rational#coerce

coerce(other) -> Array

自身と other が同じクラスになるよう、自身か other を変換し [other, self] という 配列にして返します。

[PARAM] other:
比較または変換するオブジェクト

例:

Rational(1).coerce(2)   # => [(2/1), (1/1)]
Rational(1).coerce(2.2) # => [2.2, 1.0]