るりまサーチ

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

別のキーワード

  1. etc sc_xopen_enh_i18n
  2. rsa n
  3. rsa n=
  4. pop n_bytes
  5. openssl n

ライブラリ

クラス

検索結果

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

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

...her を Float に変換して [other, self] という配列にして返します。
N
umeric のサブクラスは、このメソッドを適切に再定義しなければなりません。
以下は Rational の coerce のソースです。other が自身の知らない数値クラスであった場...
...意して下さい。


//emlist[例][ruby]{
# 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 を使って自分とオペランドを変換した上で演算を行います。
以下は Rational の + メソッドを一部省略したものです。
引数が自身の知らない数値クラスである場合、引数の coerce により自身を変換し...

OpenSSL::BN#coerce(other) -> Array (21126.0)

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

...r が整数のときに、自身を Integer のオブジェクトに
変換して [other, 変換後オブジェクト] にして返します。
それ以外の場合は例外 TypeError を発生させます。

//emlist[][ruby]{
require 'openssl'
p 1.to_bn.coerce(2) # => [2, 1]
//}

@param other...
...変換の基準となるオブジェクト
@raise TypeError 変換に失敗した場合に発生します

coerce
メソッドの詳細な説明は、Numeric#coerce にあります。
@see Numeric#coerce...

Rational#coerce(other) -> Array (21114.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]
//}...

URI::Generic#coerce(oth) -> [URI, URI] (21108.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>]...