るりまサーチ

最速Rubyリファレンスマニュアル検索!
55件ヒット [1-55件を表示] (0.319秒)
トップページ > クエリ:current[x] > クエリ:thread_variable_get[x]

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

クラス

キーワード

検索結果

Thread#thread_variable_get(key) -> object | nil (18137.0)

引数 key で指定した名前のスレッドローカル変数を返します。

...Thread.current.thread_variable_set("foo", "bar") # スレッドローカル
Thread.current["foo"] = "bar" # Fiber ローカル

Fiber.new {
Fiber.yield [
Thread.current.thread_variable_get("foo"), # スレッドローカル
Thread.current["foo"],...
...# Fiber ローカル
]
}.resume
}.join.value # => ['bar', nil]

この例の "bar" は Thread#thread_variable_get により得られ
た値で、nil はThread#[] により得られた値です。

@see Thread#thread_variable_set, Thread#[]

@see https://magazine.ruby...

Thread#[](name) -> object | nil (48.0)

name に対応したスレッドに固有のデータを取り出します。 name に対応するスレッド固有データがなければ nil を返し ます。

...のキーを文字列か Symbol で指定します。

//emlist[例][ruby]{
[
Thread.new { Thread.current["name"] = "A" },
Thread.new { Thread.current[:name] = "B" },
Thread.new { Thread.current["name"] = "C" }
].each do |th|
th.join
puts "#{th.inspect}: #{th[:name]}"
end

# => #<Thread:0...
...す事に注意してください。

//emlist[][ruby]{
def meth(newvalue)
begin
oldvalue = Thread.current[:name]
Thread.current[:name] = newvalue
yield
ensure
Thread.current[:name] = oldvalue
end
end
//}

この関数に与えるブロックがFiberを切り替える場合は...
...}
}
meth(2) {
f.resume
}
f.resume
p Thread.current[:name]
# => nil if fiber-local
# => 2 if thread-local (The value 2 is leaked to outside of meth method.)
//}

Fiber を切り替えても同じ変数を返したい場合は
Thread#thread_variable_get と Thread#thread_variable_set
を使用し...

Thread#thread_variable_set(key, value) (18.0)

引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま す。

...

//emlist[例][ruby]{
thr = Thread.new do
Thread.current.thread_variable_set(:cat, 'meow')
Thread.current.thread_variable_set("dog", 'woof')
end
thr.join # => #<Thread:0x401b3f10 dead>
thr.thread_variables # => [:dog, :cat]
//}

@see Thread#thread_variable_get, Thread#[]...

NEWS for Ruby 2.0.0 (12.0)

NEWS for Ruby 2.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...ンス変数の名前と値をハッシュのキーと値にしたハッシュを生成して返します

* Thread
* 追加: Thread#thread_variable_get スレッドローカルな変数を取得します
(these are different than Fiber local variables).
* 追加: Thread#thread_varia...
...* added method:
* added main.define_method which defines a global function.
* added main.using, which imports refinements into the current file or
eval string. [experimental]

=== 組み込みクラスの互換性 (機能追加とバグ修正を除く)

* Array#values_at...
...ment.
* Authenticated Encryption with Associated Data (AEAD) is supported via
Cipher#auth_data= and Cipher#auth_tag/Cipher#auth_tag=.
Current
ly (OpenSSL 1.0.1c), only GCM mode is supported.

* ostruct
* 追加: OpenStruct#[] , OpenStruct#[]=
* 追加: OpenStruct#each_pair...

Thread#thread_variable?(key) -> bool (12.0)

引数 key で指定した名前のスレッドローカル変数が存在する場合に true、そ うでない場合に false を返します。

...合に true、そ
うでない場合に false を返します。

@param key 変数名を String か Symbol で指定します。

me = Thread.current
me.thread_variable_set(:oliver, "a")
me.thread_variable?(:oliver) # => true
me.thread_variable?(:stanley) # => false

[注意]: Thre...

絞り込み条件を変える