るりまサーチ

最速Rubyリファレンスマニュアル検索!
333件ヒット [201-300件を表示] (0.093秒)
トップページ > クエリ:Ruby[x] > クエリ:ruby[x] > 種類:インスタンスメソッド[x] > クエリ:i[x] > クラス:Rational[x]

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

キーワード

検索結果

<< < 1 2 3 4 > >>

Rational#-@ -> Rational (3114.0)

単項演算子の - です。 self の符号を反転させたものを返します。

...単項演算子の - です。
self の符号を反転させたものを返します。

//emlist[例][ruby]{
r = Rational(3, 4)
- r # => (-3/4)
//}...

Rational#/(other) -> Rational | Float (3114.0)

商を計算します。

...//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
//}

@raise ZeroDivisionError other が 0 の時に発生します。

@see Numeric#quo...

Rational#<=>(other) -> -1 | 0 | 1 | nil (3114.0)

self と other を比較して、self が大きい時に 1、等しい時に 0、小さい時に -1 を返します。比較できない場合はnilを返します。

...場合はnilを返します。

@param other 自身と比較する数値

@return -1 か 0 か 1 か nil を返します。

//emlist[例][ruby]{
Rational
(2, 3) <=> Rational(2, 3) # => 0
Rational
(5) <=> 5 # => 0
Rational
(2, 3) <=> Rational(1,3) # => 1
Rational
(1, 3) <=>...
...1 # => -1
Rational
(1, 3) <=> 0.3 # => 1
Rational
(1, 3) <=> nil # => nil
//}...

Rational#abs -> Rational (3114.0)

自身の絶対値を返します。

...自身の絶対値を返します。

//emlist[例][ruby]{
Rational
(1, 2).abs # => (1/2)
Rational
(-1, 2).abs # => (1/2)
//}...

Rational#numerator -> Integer (3114.0)

分子を返します。

...分子を返します。

@return 分子を返します。

//emlist[例][ruby]{
Rational
(7).numerator # => 7
Rational
(7, 1).numerator # => 7
Rational
(9, -4).numerator # => -9
Rational
(-2, -10).numerator # => 1
//}

@see Rational#denominator...

絞り込み条件を変える

Rational#quo(other) -> Rational | Float (3114.0)

商を計算します。

...//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
//}

@raise ZeroDivisionError other が 0 の時に発生します。

@see Numeric#quo...

Rational#to_json(*args) -> String (3114.0)

自身を JSON 形式の文字列に変換して返します。

...JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。

@param args 使用しません。

//emlist[例][ruby]{
require 'json/add/rational'
Rational
(1, 3).to_json # => "{\"json_class\":\"Rational\",\"n\":1,\"d\":3}"
//}

@see JSON::Generator::GeneratorMethods::Hash#to_json...
...@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json
に渡されます。

//emlist[例][ruby]{
require 'json/add/rational'
Rational
(1, 3).to_json # => "{\"json_class\":\"Rational\",\"n\":1,\"d\":3}"
//}

@see JSON::Generator::GeneratorMethods::Hash#to_json...

Rational#to_r -> Rational (3114.0)

自身を返します。

...自身を返します。

@return 自身を返します。

//emlist[例][ruby]{
Rational
(3, 4).to_r # => (3/4)
Rational
(8).to_r # => (8/1)
//}...

Rational#to_s -> String (3114.0)

自身を人間が読みやすい形の文字列表現にして返します。

..."-17/7" のように10進数の表記を返します。

@return 有理数の表記にした文字列を返します。

//emlist[例][ruby]{
Rational
(3, 4).to_s # => "3/4"
Rational
(8).to_s # => "8/1"
Rational
(-8, 6).to_s # => "-4/3"
Rational
(0.5).to_s # => "1/2"
//}

@see Rational#inspect...

Rational#==(other) -> bool (3014.0)

数値として等しいか判定します。

...でなければ false を返します。

//emlist[例][ruby]{
Rational
(2, 3) == Rational(2, 3) # => true
Rational
(5) == 5 # => true
Rational
(0) == 0.0 # => true
Rational
('1/3') == 0.33 # => false
Rational
('1/2') == '1/2' # => false
//}...

絞り込み条件を変える

<< < 1 2 3 4 > >>