種類
- インスタンスメソッド (71)
- モジュール関数 (22)
クラス
- Binding (11)
- Thread (49)
- TracePoint (11)
モジュール
- ObjectSpace (22)
キーワード
-
add
_ trace _ func (11) - backtrace (11)
-
define
_ finalizer (22) -
local
_ variable _ set (11) -
report
_ on _ exception (8) -
report
_ on _ exception= (8) -
set
_ trace _ func (11)
検索結果
先頭5件
-
TracePoint
# binding -> Binding | nil (29238.0) -
発生したイベントによって生成された Binding オブジェクトを返します。
...た Binding オブジェクトを返します。
C で記述されたメソッドは binding を生成しないため、
:c_call および :c_return イベントに対しては nil を返すことに注意してください。
//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:cal......l) do |tp|
p tp.binding.local_variables # => [:ret]
end
trace.enable
foo 1
//}... -
TracePoint
# binding -> Binding (29232.0) -
発生したイベントによって生成された Binding オブジェクトを返します。
...発生したイベントによって生成された Binding オブジェクトを返します。
//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:call) do |tp|
p tp.binding.local_variables # => [:ret]
end
trace.enable
foo 1
//}... -
Binding
# local _ variable _ set(symbol , obj) (23138.0) -
引数 symbol で指定した名前のローカル変数に引数 obj を設定します。
...ます。
//emlist[例][ruby]{
def foo
a = 1
bind = binding
bind.local_variable_set(:a, 2) # set existing local variable `a'
bind.local_variable_set(:b, 3) # create new local variable `b'
# `b' exists only in binding
p bind.local_variable_get(:a) # => 2......al_variable_get(:b) # => 3
p a # => 2
p b # => NameError
end
//}
このメソッドは以下のコード(ただし、obj が Ruby のコードで出力される場
合)と同様の動作をします。
//emlist[][ruby]{
binding.eval("#{sym......bol} = #{obj}")
//}
@see Binding#local_variable_get, Binding#local_variable_defined?... -
Thread
# report _ on _ exception=(newstate) (17320.0) -
真の場合、そのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...tderr に報告します。
デフォルトはスレッド作成時の Thread.report_on_exception です。
@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false で指定します。
//emlist[例][ruby]{
a = Thread.new{ Threa......p; raise }
a.report_on_exception = true
a.report_on_exception # => true
a.run
# => #<Thread:0x00007fc3f48c7908@(irb):1 run> terminated with exception (report_on_exception is true):
# Traceback (most recent call last):
# (irb):1:in `block in irb_binding': unhandled exception
# #<Thread:0x0......0007fc3f48c7908@(irb):1 dead>
b = Thread.new{ Thread.stop; raise }
b.report_on_exception = false
b.run # => #<Thread:0x00007fc3f48aefc0@(irb):4 dead>
//}
@see Thread.report_on_exception... -
Thread
# report _ on _ exception -> bool (17220.0) -
真の場合、そのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...tderr に報告します。
デフォルトはスレッド作成時の Thread.report_on_exception です。
@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false で指定します。
//emlist[例][ruby]{
a = Thread.new{ Threa......p; raise }
a.report_on_exception = true
a.report_on_exception # => true
a.run
# => #<Thread:0x00007fc3f48c7908@(irb):1 run> terminated with exception (report_on_exception is true):
# Traceback (most recent call last):
# (irb):1:in `block in irb_binding': unhandled exception
# #<Thread:0x0......0007fc3f48c7908@(irb):1 dead>
b = Thread.new{ Thread.stop; raise }
b.report_on_exception = false
b.run # => #<Thread:0x00007fc3f48aefc0@(irb):4 dead>
//}
@see Thread.report_on_exception... -
Thread
# add _ trace _ func(pr) -> Proc (14216.0) -
スレッドにトレース用ハンドラを追加します。
...//emlist[例][ruby]{
th = Thread.new do
class Trace
end
43.to_s
end
th.add_trace_func lambda {|*arg| p arg }
th.join
# => ["line", "example.rb", 4, nil, #<Binding:0x00007f98e107d0d8>, nil]
# => ["c-call", "example.rb", 4, :inherited, #<Binding:0x00007f98e1087448>, Class]
# => ["c-return", "ex......e.rb", 4, :inherited, #<Binding:0x00007f98e1085d00>, Class]
# => ["class", "example.rb", 4, nil, #<Binding:0x00007f98e108f210>, nil]
# => ["end", "example.rb", 5, nil, #<Binding:0x00007f98e108e5e0>, nil]
# => ["line", "example.rb", 6, nil, #<Binding:0x00007f98e108d4b0>, nil]
# => ["c-call", "example.......rb", 6, :to_s, #<Binding:0x00007f98e1097aa0>, Integer]
# => ["c-return", "example.rb", 6, :to_s, #<Binding:0x00007f98e1095cc8>, Integer]
//}
@see Thread#set_trace_func Kernel.#set_trace_func... -
Thread
# set _ trace _ func(pr) -> Proc | nil (14192.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, #<Binding:0x0......7fc8de886770>, 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, #<Binding:0x0......07fc8de88c440>, 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, #<... -
ObjectSpace
. # define _ finalizer(obj) {|id| . . . } -> Array (14126.0) -
obj が解放されるときに実行されるファイナライザ proc を 登録します。同じオブジェクトについて複数回呼ばれたときは置き換えで はなく追加登録されます。固定値 0 と proc を配列にして返します。
...ックを指定した場合は、そのブロックがファイナライザになります。
obj の回収時にブロックは obj の ID (BasicObject#__id__)を引数とし
て実行されます。
しかし、後述の問題があるのでブロックでファイナライザを登録するのは......い方の注意
以下は、define_finalizer の使い方の悪い例です。
//emlist[悪い例][ruby]{
class Foo
def initialize
ObjectSpace.define_finalizer(self) {
puts "foo"
}
end
end
Foo.new
GC.start
//}
これは、渡された proc の self が obj を参照しつ
づけ......tempfile は、ファイナライザの使い方の
良い例になっています。これは、クラスのコンテキストで Proc を
生成することで上記の問題を回避しています。
//emlist[例][ruby]{
class Bar
def Bar.callback
proc {
puts "bar"
}
end
def... -
ObjectSpace
. # define _ finalizer(obj , proc) -> Array (14126.0) -
obj が解放されるときに実行されるファイナライザ proc を 登録します。同じオブジェクトについて複数回呼ばれたときは置き換えで はなく追加登録されます。固定値 0 と proc を配列にして返します。
...ックを指定した場合は、そのブロックがファイナライザになります。
obj の回収時にブロックは obj の ID (BasicObject#__id__)を引数とし
て実行されます。
しかし、後述の問題があるのでブロックでファイナライザを登録するのは......い方の注意
以下は、define_finalizer の使い方の悪い例です。
//emlist[悪い例][ruby]{
class Foo
def initialize
ObjectSpace.define_finalizer(self) {
puts "foo"
}
end
end
Foo.new
GC.start
//}
これは、渡された proc の self が obj を参照しつ
づけ......tempfile は、ファイナライザの使い方の
良い例になっています。これは、クラスのコンテキストで Proc を
生成することで上記の問題を回避しています。
//emlist[例][ruby]{
class Bar
def Bar.callback
proc {
puts "bar"
}
end
def... -
Thread
# backtrace -> [String] | nil (14120.0) -
スレッドの現在のバックトレースを返します。
...す。
//emlist[例][ruby]{
class C1
def m1
sleep 5
end
def m2
m1
end
end
th = Thread.new {C1.new.m2; Thread.stop}
th.backtrace
# => [
# [0] "(irb):3:in `sleep'",
# [1] "(irb):3:in `m1'",
# [2] "(irb):6:in `m2'",
# [3] "(irb):10:in `block in irb_binding'"
# ]......th.kill
th.backtrace # => nil
//}...