129件ヒット
[1-100件を表示]
(0.016秒)
種類
- インスタンスメソッド (108)
- モジュール関数 (21)
モジュール
- Kernel (10)
- ObjectSpace (11)
キーワード
- abort (10)
- binding (11)
- rand (33)
- receiver (9)
-
respond
_ to _ missing? (11) -
undefine
_ finalizer (11)
検索結果
先頭5件
-
Array
# sample -> object | nil (18124.0) -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
...した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
a = (1..10).to_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]
//}... -
Array
# sample(n) -> Array (18124.0) -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
...した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
a = (1..10).to_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]
//}... -
Array
# sample(n , random: Random) -> Array (18124.0) -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
...した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
a = (1..10).to_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]
//}... -
Array
# sample(random: Random) -> object | nil (18124.0) -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
...した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
a = (1..10).to_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]
//}... -
Object
# respond _ to _ missing?(symbol , include _ private) -> bool (62.0) -
自身が symbol で表されるメソッドに対し BasicObject#method_missing で反応するつもりならば真を返します。
...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 (38.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... -
NameError
# receiver -> object (20.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... -
Proc
# binding -> Binding (14.0) -
Proc オブジェクトが保持するコンテキストを Binding オブジェクトで返します。
...Proc オブジェクトが保持するコンテキストを
Binding オブジェクトで返します。
//emlist[例][ruby]{
def fred(param)
proc {}
end
sample_proc = fred(99)
eval("param", sample_proc.binding) # => 99
//}... -
Random
# rand -> Float (14.0) -
一様な擬似乱数を発生させます。
...うに見える
# 上と同じ種で再初期化
prng = Random.new(1234)
srand(1234)
# Kernel.#rand は Array#sample などの影響を受けて値がずれることがある
[0, 1].sample
prng.rand #=> 0.1915194503788923
rand #=> 0.6221087710398319
//}
@see Kernel.#r... -
Random
# rand(max) -> Integer | Float (14.0) -
一様な擬似乱数を発生させます。
...うに見える
# 上と同じ種で再初期化
prng = Random.new(1234)
srand(1234)
# Kernel.#rand は Array#sample などの影響を受けて値がずれることがある
[0, 1].sample
prng.rand #=> 0.1915194503788923
rand #=> 0.6221087710398319
//}
@see Kernel.#r...