るりまサーチ

最速Rubyリファレンスマニュアル検索!
33件ヒット [1-33件を表示] (0.047秒)

別のキーワード

  1. _builtin coerce
  2. matrix coerce
  3. bigdecimal coerce
  4. bn coerce
  5. uri coerce

クラス

検索結果

Numeric#coerce(other) -> [Numeric] (18134.0)

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

...ばなりません。
以下は Rational の coerce のソースです。other が自身の知らない数値クラスであった場合、
super を呼んでいることに注意して下さい。


//emlist[例][ruby]{
# lib/rational.rb より

def coerce(other)
if other.kind_of?(Float)
retu...
...ドとして受け
取ると coerce を使って自分とオペランドを変換した上で演算を行います。
以下は Rational の + メソッドを一部省略したものです。
引数が自身の知らない数値クラスである場合、引数の coerce により自身を変換し...
...b/rational.rb より

def + (a)
if a.kind_of?(Rational)
# 長いので省略
elsif a.kind_of?(Integer)
# 長いので省略
elsif a.kind_of?(Float)
Float(self) + a
else
x, y = a.coerce(self)
x + y
end
end
//}

@param other オペランドを数値で指定します。...

Rational#coerce(other) -> Array (18116.0)

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

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

@param other 比較または変換するオブジェクト

//emlist[例][ruby]{
Rational(1).coerce(2) # => [(2/1), (1/1)]
Rational(1).coerce(2.2) # => [2.2, 1.0]
//}...

Complex#coerce(other) -> [Complex, Complex] (18110.0)

other を Complex に変換して [変換後の other, self] の配列を返します。

...other を Complex に変換して [変換後の other, self] の配列を返します。

@raise TypeError 変換できないオブジェクトを指定した場合に発生します。

//emlist[例][ruby]{
Complex(1).coerce(2) # => [(2+0i), (1+0i)]
//}...