るりまサーチ

最速Rubyリファレンスマニュアル検索!
106件ヒット [1-100件を表示] (0.033秒)

別のキーワード

  1. objectspace each_object
  2. _builtin each_object
  3. object send
  4. object to_enum
  5. object enum_for

ライブラリ

クラス

キーワード

検索結果

<< 1 2 > >>

Array#sample -> object | nil (18331.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando...
...m: SecureRandom) #=> 2
//}...

Array#sample(random: Random) -> object | nil (18331.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando...
...m: SecureRandom) #=> 2
//}...

Array#sample(n) -> Array (18231.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando...
...m: SecureRandom) #=> 2
//}...

Array#sample(n, random: Random) -> Array (18231.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}

random SecureRandom などの乱数生成器を渡すことができます。

//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando...
...m: SecureRandom) #=> 2
//}...

Object#respond_to_missing?(symbol, include_private) -> bool (9173.0)

自身が symbol で表されるメソッドに対し BasicObject#method_missing で反応するつもりならば真を返します。

...れるメソッドに対し
BasicObject#method_missing で反応するつもりならば真を返します。

Object
#respond_to? はメソッドが定義されていない場合、
デフォルトでこのメソッドを呼びだし問合せます。

BasicObject#method_missing を override した...
...class Sample
def method_missing(name, *args)
if name =~ /^to_*/
[name, *args] # => [:to_sample, "sample args1", "sample args2"]
return
else
super
end
end

def respond_to_missing?(sym, include_private)
(sym =~ /^to_*/) ? true : super
end
end

s = Sample.new...
...s.to_sample("sample args1", "sample args2")
s.respond_to?(:to_sample) # => true
s.respond_to?(:sample) # => false
//}

@see Object#respond_to?, BasicObject#method_missing...

絞り込み条件を変える

NameError#receiver -> object (226.0)

self が発生した時のレシーバオブジェクトを返します。

...lf が発生した時のレシーバオブジェクトを返します。

例:

class Sample
def foo
return "foo"
end
end

bar = Sample.new
begin
bar.bar
rescue NameError => err
p err.receiver # => #<Sample:0x007fd4d89b3110>
p err.receiver.foo # => "foo"
end...

Random#rand -> Float (119.0)

一様な擬似乱数を発生させます。

...も同様です。
このため range が Time の場合などにもうまく動作します。

引数が実数でも範囲でもない場合は Object#to_int で変換した値が指定されたものとして扱います。

@param max 乱数値の上限を正の整数または実数で指定...
...prng = Random.new(1234)
prng.rand # => 0.1915194503788923
srand(1234)
rand # => 0.1915194503788923

# max に実数も指定出来る
prng.rand(6.5) # => 4.043707011758907
# (rand(6) と同等)
rand(6.5) # => 5

# 引数には Range も指定できる
# 0...
.....10) # => 4
# 0 から 9までの整数が得られる
prng.rand(0...10) # => 8
# 0 から 4.2までの実数が得られる (4.2 が得られる可能性もある)
prng.rand(0..4.2) # => 3.2397116600246867
# 0 から 4.2までの実数が得られる (4.2 は除く)
prng.rand(0...4.2) # => 3.61481...

Random#rand(max) -> Integer | Float (119.0)

一様な擬似乱数を発生させます。

...も同様です。
このため range が Time の場合などにもうまく動作します。

引数が実数でも範囲でもない場合は Object#to_int で変換した値が指定されたものとして扱います。

@param max 乱数値の上限を正の整数または実数で指定...
...prng = Random.new(1234)
prng.rand # => 0.1915194503788923
srand(1234)
rand # => 0.1915194503788923

# max に実数も指定出来る
prng.rand(6.5) # => 4.043707011758907
# (rand(6) と同等)
rand(6.5) # => 5

# 引数には Range も指定できる
# 0...
.....10) # => 4
# 0 から 9までの整数が得られる
prng.rand(0...10) # => 8
# 0 から 4.2までの実数が得られる (4.2 が得られる可能性もある)
prng.rand(0..4.2) # => 3.2397116600246867
# 0 から 4.2までの実数が得られる (4.2 は除く)
prng.rand(0...4.2) # => 3.61481...

Random#rand(range) -> Integer | Float (119.0)

一様な擬似乱数を発生させます。

...も同様です。
このため range が Time の場合などにもうまく動作します。

引数が実数でも範囲でもない場合は Object#to_int で変換した値が指定されたものとして扱います。

@param max 乱数値の上限を正の整数または実数で指定...
...prng = Random.new(1234)
prng.rand # => 0.1915194503788923
srand(1234)
rand # => 0.1915194503788923

# max に実数も指定出来る
prng.rand(6.5) # => 4.043707011758907
# (rand(6) と同等)
rand(6.5) # => 5

# 引数には Range も指定できる
# 0...
.....10) # => 4
# 0 から 9までの整数が得られる
prng.rand(0...10) # => 8
# 0 から 4.2までの実数が得られる (4.2 が得られる可能性もある)
prng.rand(0..4.2) # => 3.2397116600246867
# 0 から 4.2までの実数が得られる (4.2 は除く)
prng.rand(0...4.2) # => 3.61481...
<< 1 2 > >>