238件ヒット
[1-100件を表示]
(0.204秒)
種類
- インスタンスメソッド (175)
- 特異メソッド (45)
- クラス (11)
- 変数 (7)
キーワード
-
$ SAFE (7) - ThreadGroup (11)
- [] (11)
- alive? (11)
- define (4)
- exec (11)
- fetch (7)
- group (11)
- inspect (11)
- key? (11)
- keys (11)
- priority (11)
- priority= (11)
-
report
_ on _ exception (8) -
report
_ on _ exception= (8) -
safe
_ level (7) -
set
_ trace _ func (11) - status (11)
- stop? (11)
-
thread
_ variable? (11) -
thread
_ variable _ get (11) -
thread
_ variable _ set (11) -
to
_ s (7)
検索結果
先頭5件
-
Fiber
. current -> Fiber (32233.0) -
このメソッドが評価されたコンテキストにおける Fiber のインスタンスを返します。
...のメソッドが評価されたコンテキストにおける Fiber のインスタンスを返します。
//emlist[例:][ruby]{
fr = Fiber.new do
Fiber.current
end
fb = fr.resume
p fb.equal?(fr) # => true
p Fiber.current # => #<Fiber:0x91345e4>
p Fiber.current # => #<Fiber:0x91345e4>
//}... -
Thread
. current -> Thread (32215.0) -
現在実行中のスレッド(カレントスレッド)を返します。
...現在実行中のスレッド(カレントスレッド)を返します。
p Thread.current #=> #<Thread:0x4022e6fc run>... -
Thread
. report _ on _ exception -> bool (17220.0) -
真の時は、いずれかのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...を $stderr に報告します。
デフォルトは false です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `block......in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が......で rescue して、
その例外でスレッドが終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception = false でレ......容を $stderr に報告します。
デフォルトは true です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `blo......ck in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が... -
Thread
. report _ on _ exception=(newstate) (17220.0) -
真の時は、いずれかのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...を $stderr に報告します。
デフォルトは false です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `block......in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が......で rescue して、
その例外でスレッドが終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception = false でレ......容を $stderr に報告します。
デフォルトは true です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `blo......ck in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が... -
Thread
# thread _ variable _ get(key) -> object | nil (17126.0) -
引数 key で指定した名前のスレッドローカル変数を返します。
...key で指定した名前のスレッドローカル変数を返します。
[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、Fiber を切り替えても同じ変数を返す事に注意してください。
例:
Thread.new {
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.rubyist.net/articles/00... -
Thread
# thread _ variable _ set(key , value) (17114.0) -
引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま す。
...引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま
す。
[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、セットした変数は Fiber を切り替えても共通で使える事に注意してく......。
//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#[]... -
Thread
# thread _ variable?(key) -> bool (17108.0) -
引数 key で指定した名前のスレッドローカル変数が存在する場合に true、そ うでない場合に false を返します。
...key で指定した名前のスレッドローカル変数が存在する場合に 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
[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)が
対象ではない事に注意してください。
@see Thread#thread_variable_get, Thread#[]... -
Thread
# set _ trace _ func(pr) -> Proc | nil (14132.0) -
スレッドにトレース用ハンドラを設定します。
...す。
//emlist[例][ruby]{
th = Thread.new do
class Trace
end
2.to_s
Thread.current.set_trace_func nil
3.to_s
end
th.set_trace_func lambda {|*arg| p arg }
th.join
# => ["line", "example.rb", 2, nil, #<Binding:0x00007fc8de87cb08>, nil]
# => ["c-call", "example.rb", 2, :inherited, #<Bindi......ng:0x00007fc8de886770>, Class]
# => ["c-return", "example.rb", 2, :inherited, #<Binding:0x00007fc8de8844e8>, Class]
# => ["class", "example.rb", 2, nil, #<Binding:0x00007fc8de88e830>, nil]
# => ["end", "example.rb", 3, nil, #<Binding:0x00007fc8de88d6b0>, nil]
# => ["line", "example.rb", 4, nil, #<Bi......7fc8de88c440>, nil]
# => ["c-call", "example.rb", 4, :to_s, #<Binding:0x00007fc8de896f30>, Integer]
# => ["c-return", "example.rb", 4, :to_s, #<Binding:0x00007fc8de894a50>, Integer]
# => ["line", "example.rb", 5, nil, #<Binding:0x00007fc8de967b08>, nil]
# => ["c-call", "example.rb", 5, :current, #<B... -
Data
. define(*args) -> Class (14114.0) -
Data クラスに新しいサブクラスを作って、それを返します。
...//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
p fred.name # => "Fred"
p fred.age # => 5
//}
メンバの値を書き換えることはできません。
//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
fred.age = 6 # => NoMethodError......//emlist[例][ruby]{
class HTTPFetcher
Response = Data.define(:body)
NotFound = Data.define
def get(url)
# ダミーの実装
if url == "http://example.com/"
Response.new(body: "Current time is #{Time.now}")
else
NotFound.new
end
end
end
def fetch(url)
fetcher......= HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body
in HTTPFetcher::NotFound
:NotFound
end
end
p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFound
//}
@param args 値オブジ... -
Data
. define(*args) {|subclass| block } -> Class (14114.0) -
Data クラスに新しいサブクラスを作って、それを返します。
...//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
p fred.name # => "Fred"
p fred.age # => 5
//}
メンバの値を書き換えることはできません。
//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
fred.age = 6 # => NoMethodError......//emlist[例][ruby]{
class HTTPFetcher
Response = Data.define(:body)
NotFound = Data.define
def get(url)
# ダミーの実装
if url == "http://example.com/"
Response.new(body: "Current time is #{Time.now}")
else
NotFound.new
end
end
end
def fetch(url)
fetcher......= HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body
in HTTPFetcher::NotFound
:NotFound
end
end
p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFound
//}
@param args 値オブジ... -
Kernel
$ $ SAFE -> Integer (14108.0) -
カレントスレッドのセーフレベルを表す整数です。
...のセーフレベルを表す整数です。
セーフレベルについてはspec/safelevel を参照してください。
Thread.current.safe_level と同じです。
非整数を代入しようとすると TypeError が発生します。
この変数はスレッドローカルです。
Ruby......のセーフレベルを表す整数です。
セーフレベルについてはspec/safelevel を参照してください。
Thread.current.safe_level と同じです。
非整数を代入しようとすると TypeError が発生します。
この変数はグローバルスコープです。
Rub... -
Process
. exec(command , *args) -> () (14108.0) -
カレントプロセスを与えられた外部コマンドで置き換えます。
...き換えます。
=== 引数の解釈
引数が一つだけ与えられた場合、command が shell のメタ文字
//emlist{
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
//}
を含む場合、shell 経由で実行されます。
そうでなければインタプリタから直接実行されます...... exec(2) を使用して実行されるので元の
プログラムからいくつかの環境を引き継ぎます。
@param command 実行する外部コマンド。
@param args command に渡す引数。
exec "echo *" # echoes list of files in current directory
# never get here......exec "echo", "*" # echoes an asterisk
# never get here... -
Thread
# alive? -> bool (14108.0) -
スレッドが「生きている」時、true を返します。
...」時、true を返します。
例:
thr = Thread.new { }
thr.join # => #<Thread:0x401b3fb0 dead>
Thread.current.alive? # => true
thr.alive? # => false
Thread#status が真を返すなら、このメソッドも真です。
@see Thread#status, Thread#stop?...