77件ヒット
[1-77件を表示]
(0.030秒)
種類
- インスタンスメソッド (55)
- クラス (11)
- モジュール関数 (11)
モジュール
- Kernel (11)
検索結果
先頭5件
-
Rational (38068.0)
-
有理数を扱うクラスです。
...様に Rational.new ではなく、 Kernel.#Rational を使用して
Rational オブジェクトを作成します。
//emlist[例][ruby]{
Rational(1, 3) # => (1/3)
Rational('1/3') # => (1/3)
Rational('0.33') # => (33/100)
Rational.new(1, 3) # => NoMethodError
//}
Rational オブ......ジェクトは常に既約(それ以上約分できない状態)である
事に注意してください。
//emlist[例][ruby]{
Rational(2, 6) # => (1/3)
Rational(1, 3) * 3 # => (1/1)
//}... -
Kernel
. # Rational(x , y = 1) -> Rational (27394.0) -
引数を有理数(Rational)に変換した結果を返します。
...引数を有理数(Rational)に変換した結果を返します。
@param x 変換対象のオブジェクトです。
@param y 変換対象のオブジェクトです。省略した場合は x だけを用いて
Rational オブジェクトを作成します。
@raise ArgumentError......x/y した Rational オブジェクトを
返します。
//emlist[例][ruby]{
Rational("1/3") # => (1/3)
Rational(1, 3) # => (1/3)
Rational("0.1", "0.3") # => (1/3)
Rational(Complex(1,2), 2) # => ((1/2)+(1/1)*i)
//}
ただし、1.8系とは異なり、Rational オブジェ......クトは常に既約(それ以上
約分できない状態)である事に注意してください。
//emlist[例][ruby]{
Rational(2, 6) # => (1/3)
Rational(1, 3) * 3 # => (1/1)
//}
引数に文字列を指定する場合、以下のいずれかの形式で指定します。
* "1/3... -
Kernel
. # Rational(x , y = 1 , exception: true) -> Rational | nil (27394.0) -
引数を有理数(Rational)に変換した結果を返します。
...引数を有理数(Rational)に変換した結果を返します。
@param x 変換対象のオブジェクトです。
@param y 変換対象のオブジェクトです。省略した場合は x だけを用いて
Rational オブジェクトを作成します。
@param exception false......x/y した Rational オブジェクトを
返します。
//emlist[例][ruby]{
Rational("1/3") # => (1/3)
Rational(1, 3) # => (1/3)
Rational("0.1", "0.3") # => (1/3)
Rational(Complex(1,2), 2) # => ((1/2)+(1/1)*i)
//}
ただし、1.8系とは異なり、Rational オブジェ......クトは常に既約(それ以上
約分できない状態)である事に注意してください。
//emlist[例][ruby]{
Rational(2, 6) # => (1/3)
Rational(1, 3) * 3 # => (1/1)
//}
引数に文字列を指定する場合、以下のいずれかの形式で指定します。
* "1/3... -
Rational
# convert(*arg) -> Rational (21143.0) -
引数を有理数(Rational)に変換した結果を返します。
...引数を有理数(Rational)に変換した結果を返します。
@param arg 変換対象のオブジェクトです。
Kernel.#Rational の本体です。
@see Kernel.#Rational... -
String
# to _ r -> Rational (155.0) -
自身を有理数(Rational)に変換した結果を返します。
...自身を有理数(Rational)に変換した結果を返します。
Kernel.#Rational に文字列を指定した時のように、以下のいずれかの形
式で指定します。
* "1/3" のような分数の形式
* "0.3" のような10進数の形式
* "0.3E0" のような x.xEn の形......)
'-9.2'.to_r # => (-46/5)
'-9.2E2'.to_r # => (-920/1)
'1_234_567'.to_r # => (1234567/1)
'1_234/5_678'.to_r # => (617/2839)
//}
Kernel.#Rational に文字列を指定した時とは異なる点もあります。
途中に変換できないような文字列が入っていた場合は......# => (21/1)
'21/06/09'.to_r # => (7/2) # 21/6 を約分して 7/2。
//}
変換できないような文字列を指定した場合は 0/1 を返します。
//emlist[][ruby]{
'foo'.to_r # => (0/1)
''.to_r # => (0/1)
'bwv 1079'.to_r # => (0/1)
//}
@see Kernel.#Rational... -
Random
# rand -> Float (44.0) -
一様な擬似乱数を発生させます。
...に負の数値を与えた時や (1..0) のような値が存在しない範囲を渡した時などに発生します。
//emlist[例][ruby]{
# Kernel.#rand とほぼ同様の使い勝手
prng = Random.new(1234)
prng.rand # => 0.1915194503788923
srand(1234)
rand # => 0.......-25 03:11:42 +0900
require 'date'
prng.rand(Date.new(2012, 1, 1) ... Date.new(2013,1,1)) # => #<Date: 2012-01-31 ((2455958j,0s,0n),+0s,2299161j)>
# Kernel.#rand とほぼ同様の使い勝手
prng = Random.new(1234)
prng.rand # => 0.1915194503788923
srand(1234)
rand # => 0......いうのは DateTime#- は
# Rational を返すため。
# Date#- も Rational を返すが通常は整数を表す Rational オブジェクトを返すためうまくいくように見える
# 上と同じ種で再初期化
prng = Random.new(1234)
srand(1234)
# Kernel.#rand は Array#sample な... -
Random
# rand(max) -> Integer | Float (44.0) -
一様な擬似乱数を発生させます。
...に負の数値を与えた時や (1..0) のような値が存在しない範囲を渡した時などに発生します。
//emlist[例][ruby]{
# Kernel.#rand とほぼ同様の使い勝手
prng = Random.new(1234)
prng.rand # => 0.1915194503788923
srand(1234)
rand # => 0.......-25 03:11:42 +0900
require 'date'
prng.rand(Date.new(2012, 1, 1) ... Date.new(2013,1,1)) # => #<Date: 2012-01-31 ((2455958j,0s,0n),+0s,2299161j)>
# Kernel.#rand とほぼ同様の使い勝手
prng = Random.new(1234)
prng.rand # => 0.1915194503788923
srand(1234)
rand # => 0......いうのは DateTime#- は
# Rational を返すため。
# Date#- も Rational を返すが通常は整数を表す Rational オブジェクトを返すためうまくいくように見える
# 上と同じ種で再初期化
prng = Random.new(1234)
srand(1234)
# Kernel.#rand は Array#sample な... -
Random
# rand(range) -> Integer | Float (44.0) -
一様な擬似乱数を発生させます。
...に負の数値を与えた時や (1..0) のような値が存在しない範囲を渡した時などに発生します。
//emlist[例][ruby]{
# Kernel.#rand とほぼ同様の使い勝手
prng = Random.new(1234)
prng.rand # => 0.1915194503788923
srand(1234)
rand # => 0.......-25 03:11:42 +0900
require 'date'
prng.rand(Date.new(2012, 1, 1) ... Date.new(2013,1,1)) # => #<Date: 2012-01-31 ((2455958j,0s,0n),+0s,2299161j)>
# Kernel.#rand とほぼ同様の使い勝手
prng = Random.new(1234)
prng.rand # => 0.1915194503788923
srand(1234)
rand # => 0......いうのは DateTime#- は
# Rational を返すため。
# Date#- も Rational を返すが通常は整数を表す Rational オブジェクトを返すためうまくいくように見える
# 上と同じ種で再初期化
prng = Random.new(1234)
srand(1234)
# Kernel.#rand は Array#sample な...