104件ヒット
[1-100件を表示]
(0.049秒)
別のキーワード
種類
- インスタンスメソッド (82)
- モジュール関数 (12)
- 文書 (10)
ライブラリ
- ビルトイン (94)
モジュール
- ObjectSpace (12)
キーワード
-
NEWS for Ruby 2
. 3 . 0 (10) - rand (36)
- receiver (10)
-
respond
_ to _ missing? (12) -
undefine
_ finalizer (12)
検索結果
先頭5件
-
Array
# sample -> object | nil (18228.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... -
Array
# sample(random: Random) -> object | nil (18228.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... -
ObjectSpace
. # undefine _ finalizer(obj) -> object (3136.0) -
obj に対するファイナライザをすべて解除します。 obj を返します。
...obj に対するファイナライザをすべて解除します。
obj を返します。
@param obj ファイナライザを解除したいオブジェクトを指定します。
//emlist[例][ruby]{
class Sample
def Sample.callback
proc {
puts "finalize"
}
end
def initiali......ze
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.start
# ※何も出力されない
//}
@see ObjectSpace.#define_finalizer... -
Object
# respond _ to _ missing?(symbol , include _ private) -> bool (3060.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 (118.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 (24.0) -
一様な擬似乱数を発生させます。
...も同様です。
このため range が Time の場合などにもうまく動作します。
引数が実数でも範囲でもない場合は Object#to_int で変換した値が指定されたものとして扱います。
@param max 乱数値の上限を正の整数または実数で指定......1,1)) # => 2012-02-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......うに見える
# 上と同じ種で再初期化
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 (24.0) -
一様な擬似乱数を発生させます。
...も同様です。
このため range が Time の場合などにもうまく動作します。
引数が実数でも範囲でもない場合は Object#to_int で変換した値が指定されたものとして扱います。
@param max 乱数値の上限を正の整数または実数で指定......1,1)) # => 2012-02-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......うに見える
# 上と同じ種で再初期化
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(range) -> Integer | Float (24.0) -
一様な擬似乱数を発生させます。
...も同様です。
このため range が Time の場合などにもうまく動作します。
引数が実数でも範囲でもない場合は Object#to_int で変換した値が指定されたものとして扱います。
@param max 乱数値の上限を正の整数または実数で指定......1,1)) # => 2012-02-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......うに見える
# 上と同じ種で再初期化
prng = Random.new(1234)
srand(1234)
# Kernel.#rand は Array#sample などの影響を受けて値がずれることがある
[0, 1].sample
prng.rand #=> 0.1915194503788923
rand #=> 0.6221087710398319
//}
@see Kernel.#r... -
NEWS for Ruby 2
. 3 . 0 (18.0) -
NEWS for Ruby 2.3.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...位置を表示します。
11725
* safe navigation operator (ぼっち演算子):
* object&.foo という形式のメソッド呼び出し形式が追加されました。これは object が nil でないときにメソッド foo を呼び出します。
Active Support の try!......11537
//emlist{
obj.try! {} # valid
obj&. {} # syntax error
//}
* 引数はメソッドが呼び出された場合のみ評価されます。
//emlist{
obj.try!(:foo, bar()) # bar() は常に評価されます
obj&.foo(bar()) # bar() は......nSequence
* 実験的な機能としてiseqローダー用の低レベルな操作をするメソッドをいくつか追加
使用例は sample/iseq_loader.rb を見てください。
ローダーには検証機能がないので、編集したバイナリや壊れたバイナリを...