るりまサーチ

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

ライブラリ

キーワード

検索結果

<< < 1 2 3 4 > >>

Rational#to_json(*args) -> String (14.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::Gener...

Rational#to_s -> String (14.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) -> Rational | Float (8.0)

積を計算します。

...します。

@
param other 自身に掛ける数

other に Float を指定した場合は、計算結果を Float で返しま
す。

//emlist[例][ruby]{
r = Rational(3, 4)
r * 2 # => (3/2)
r * 4 # => (3/1)
r * 0.5 # => 0.375
r * Rational(1, 2) # => (3...

Rational#**(other) -> Rational | Float (8.0)

冪(べき)乗を計算します。

...す。

@
param other 自身を other 乗する数

other に Float を指定した場合は、計算結果を Float で返しま
す。other が有理数であっても、計算結果が無理数だった場合は Float
を返します。

//emlist[例][ruby]{
r = Rational(3, 4)
r ** Rational(2, 1)...
...# => (9/16)
r ** 2 # => (9/16)
r ** 2.0 # => 0.5625
r ** Rational(1, 2) # => 0.866025403784439
//}...

Rational#+(other) -> Rational | Float (8.0)

和を計算します。

...和を計算します。

@
param other 自身に足す数

other に Float を指定した場合は、計算結果を Float で返しま
す。

//emlist[例][ruby]{
r = Rational(3, 4)
r + Rational(1, 2) # => (5/4)
r + 1 # => (7/4)
r + 0.5 # => 1.25
//}...

絞り込み条件を変える

Rational#-(other) -> Rational | Float (8.0)

差を計算します。

...差を計算します。

@
param other 自身から引く数

other に Float を指定した場合は、計算結果を Float で返しま
す。

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

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

Rational#fdiv(other) -> Float (8.0)

self を other で割った商を Float で返します。 other に虚数を指定することは出来ません。

...は出来ません。

@
param other 自身を割る数

//emlist[例][ruby]{
Rational
(2, 3).fdiv(1) # => 0.6666666666666666
Rational
(2, 3).fdiv(0.5) # => 1.3333333333333333
Rational
(2).fdiv(3) # => 0.6666666666666666

Rational
(1).fdiv(Complex(1, 0)) # => 1.0
Rational
(1).fdiv(Complex(0, 1))...

Rational#negative? -> bool (8.0)

self が 0 未満の場合に true を返します。そうでない場合に false を返します。

...self が 0 未満の場合に true を返します。そうでない場合に false を返します。

//emlist[例][ruby]{
Rational
(1, 2).negative? # => false
Rational
(-1, 2).negative? # => true
//}

@
see Rational#positive?...

Rational#positive? -> bool (8.0)

self が 0 より大きい場合に true を返します。そうでない場合に false を返します。

...self が 0 より大きい場合に true を返します。そうでない場合に false を返します。

//emlist[例][ruby]{
Rational
(1, 2).positive? # => true
Rational
(-1, 2).positive? # => false
//}

@
see Rational#negative?...

絞り込み条件を変える

<< < 1 2 3 4 > >>