118件ヒット
[1-100件を表示]
(0.035秒)
種類
- インスタンスメソッド (106)
- モジュール関数 (12)
モジュール
- ObjectSpace (12)
キーワード
- rand (36)
- receiver (10)
-
respond
_ to _ missing? (12) -
undefine
_ finalizer (12)
検索結果
先頭5件
-
Array
# sample -> object | nil (18332.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 (18332.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 (18232.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 (18232.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 (9174.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... -
ObjectSpace
. # undefine _ finalizer(obj) -> object (3239.0) -
obj に対するファイナライザをすべて解除します。 obj を返します。
...][ruby]{
class Sample
def Sample.callback
proc {
puts "finalize"
}
end
def initialize
ObjectSpace.define_finalizer(self, Sample.callback)
end
def undef
ObjectSpace.undefine_finalizer(self)
end
end
Sample.new
GC.start
# => finalize
Sample.new
sample.undef
GC.star......t
# ※何も出力されない
//}
@see ObjectSpace.#define_finalizer... -
NameError
# receiver -> object (227.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 (120.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 (120.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...