るりまサーチ

最速Rubyリファレンスマニュアル検索!
40件ヒット [1-40件を表示] (0.076秒)
トップページ > クエリ:-[x] > クエリ:of[x] > クエリ:coerce[x]

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method new
  4. irb/input-method gets
  5. matrix -

ライブラリ

クラス

キーワード

検索結果

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

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

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


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

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

Ruby用語集 (162.0)

Ruby用語集 A B C D E F G I J M N O R S Y

...l#percent

: 0 オリジン
: zero-based
番号が 0 から始まること。

例えば、
Array や Vector、Matrix などの要素の番号、
String における文字の位置、
といったものは 0 オリジンである。

: 1 オリジン
: one-based
番号が 1 から始ま...
...e。

Bundler 自体も gem として配布されているが、Ruby 2.6 で標準添付
ライブラリーに追加された。

===[a:C] C

: Coerce
異なるクラスの値同士の演算を効率よく実装するための手法の一つ。

例えば新しい数値クラス N を定義...
...ラスのインスタンスという。

あるオブジェクトがあるクラスのインスタンスであるかどうかは Object#instance_of? で
確認できる。

なお、あるクラスの子孫クラスのインスタンスをも元のクラスの
インスタンスと呼ぶ場...

NEWS for Ruby 2.5.0 (150.0)

NEWS for Ruby 2.5.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...は参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリストは ChangeLog ファイルか bugs.ruby-lang.org の issue を参照してください。

== 2.4.0 以降の変更

=== 言語仕様の変更

* トップレベルの定数参照を削除...
...い引数が与えられたときcoerce内部で発生したエラーを隠蔽しないようになりました。
7688
* 数値の比較メソッド(<,<=,>=,>)は、coerceメソッドで発生した例外を隠蔽しなくなりました。
coerce
がnilを返す場合、変換は不...
...* Preserve time zone offset when deserializing times
https://github.com/ruby/psych/pull/316
* Remove deprecated method aliases for syck gem
https://github.com/ruby/psych/pull/312

* rbconfig
* RbConfig::LIMITS is added to provide the limits of C types.
This is...

bigdecimal (126.0)

bigdecimal は浮動小数点数演算ライブラリです。 任意の精度で 10 進表現された浮動小数点数を扱えます。

...sum = sum + BigDecimal("0.0001")
end
print sum # => 0.1e1
//}

//emlist[例3: 1.2 - 1.0 と 0.2 との比較][ruby]{
require "bigdecimal"

(BigDecimal("1.2") - BigDecimal("1.0")) == BigDecimal("0.2") # => true

(1.2 - 1.0) == 0.2 # => false
//}

=== 特別な値

正確な計算結果の提供の...
...//emlist[][ruby]{
require "bigdecimal"
BigDecimal("0.0") == BigDecimal("-0.0") # => true

1 / BigDecimal("0.0") # => Infinity
1 / BigDecimal("-0.0") # => -Infinity
//}


=== 他の数値オブジェクトとの変換 (coerce)

BigDecimal オブジェクトが算術演算子の左にあるとき...
..... (the number of times that a circle's diameter
# will fit around the circle) using J. Machin's formula.
#
def big_pi(sig) # sig: Number of significant figures
exp = -sig
pi = BigDecimal("0")
two = BigDecimal("2")
m25 = BigDecimal("-0.04")
m57121 = BigDecimal("-57121")

u =...