22件ヒット
[1-22件を表示]
(0.134秒)
クラス
- Numeric (11)
-
URI
:: Generic (11)
検索結果
-
URI
:: Generic # coerce(oth) -> [URI , URI] (21308.0) -
引数 oth をパースして [パース後の oth, self] の配列を返します。
...返します。
@param oth URI オブジェクトか文字列を指定します。
例:
require 'uri'
uri = URI.parse("http://my.example.com")
uri.coerce("http://foo.com")
# => [#<URI::HTTP:0x00000000bcb028 URL:http://foo.com/>, #<URI::HTTP:0x00000000d92178 URL:http://my.example.com>]... -
Numeric
# coerce(other) -> [Numeric] (21232.0) -
自身と other が同じクラスになるよう、自身か other を変換し [other, self] という配列にして返します。
...Numeric のサブクラスは、このメソッドを適切に再定義しなければなりません。
以下は Rational の coerce のソースです。other が自身の知らない数値クラスであった場合、
super を呼んでいることに注意して下さい。
//emlist[例][rub......y]{
# lib/rational.rb より
def coerce(other)
if other.kind_of?(Float)
return other, self.to_f
elsif other.kind_of?(Integer)
return Rational.new!(other, 1), self
else
super
end
end
//}
数値クラスの算術演算子は通常自分と演算できないクラスをオペラ......省略したものです。
引数が自身の知らない数値クラスである場合、引数の coerce により自身を変換してから
+ 演算子を呼んでいます。
//emlist[例][ruby]{
# lib/rational.rb より
def + (a)
if a.kind_of?(Rational)
# 長いので省略
elsif a....