るりまサーチ

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

別のキーワード

  1. _builtin to_s
  2. openssl to_der
  3. openssl to_s
  4. _builtin to_a
  5. openssl to_pem

ライブラリ

クラス

キーワード

検索結果

Numeric (38196.0)

数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。

...スです。Integer や Float などの数値クラス
Numeric のサブクラスとして実装されています。

演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッドは、サブクラスで...
...のクラスを参照してください。


=> ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
Numeric
Integer Fixnum Bignum Float Rational Complex
----------------------------------------------------------------------------------...
...- - - -
to_c | o - - - - - o
to_f
| - - o o o o o
to_i | - o -...
...れのクラスを参照してください。


=> ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin15]
Numeric
Integer Float Rational Complex
--------------------------------------------------------------------------------...
...to_c | o - - - o
to_f
| - o o o o
Numeric
Integer Float Rational Complex
--------------------------------------------------------------...

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

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

...other を Float に変換して [other, self] という配列にして返します。
Numeric
のサブクラスは、このメソッドを適切に再定義しなければなりません。
以下は 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
//}

数値クラスの算術...
... Rational の + メソッドを一部省略したものです。
引数が自身の知らない数値クラスである場合、引数の coerce により自身を変換してから
+ 演算子を呼んでいます。

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

def + (a)
if a.kind_of?(Rational...

NEWS for Ruby 2.6.0 (30.0)

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

...スです。
Python のスライスのようなものを表現するために使えます。
このクラスのインスタンスは Numeric#step や Range#step で得られます。

* Enumerator::Chain
* 1個の Enumerator で複数の Enumerable の連鎖を表現する新しい...
...名として追加されました。 14594
* 新規オプション
* Kernel.#Complex, Kernel.#Float, Kernel.#Integer,
Kernel.#Rational にエラー処理方法を指定する :exception オプションが
追加されました。 12732
* Kernel.#system に失敗時に...
...文字列を Kernel.#Float() のように
パースするようになりました。
* String#to_d がレシーバの文字列を String#to_f のように
パースするようになりました。
* BigDecimal.new はバージョン 2.0 で削除予定です。

* Pathname...