るりまサーチ

最速Rubyリファレンスマニュアル検索!
237件ヒット [1-100件を表示] (0.071秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:p[x] > クエリ:TracePoint[x]

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. kernel p
  5. kernel $-p

クラス

キーワード

検索結果

<< 1 2 3 > >>

TracePoint (44056.0)

Kernel.#set_trace_func と同様の機能をオブジェクト指向的な API で 提供するクラスです。

...様の機能をオブジェクト指向的な API で
提供するクラスです。

//emlist[例:例外に関する情報を収集する][ruby]{
trace = TracePoint.new(:raise) do |tp|
p
[tp.lineno, tp.event, tp.raised_exception]
end
# => #<TracePoint:0x007f786a452448>

trace.enable
# => false

0...
...divided by 0>]
//}

TracePoint
.new または、TracePoint.trace で指定したブロック
は、メソッドの引数(上記の例では :raise)に対応するイベントが発生した時に
呼び出されます。

発生するイベントの詳細については、TracePoint.new を参照し...
...ンダー #12 TracePoint の紹介 (1): https://www.atdot.net/~ko1/diary/201212.html#d12
* Ruby VM アドベントカレンダー #13 TracePoint の紹介 (2): https://www.atdot.net/~ko1/diary/201212.html#d13
* Ruby VM アドベントカレンダー #14 TracePoint の紹介 (3): https://www.atdot....

TracePoint#raised_exception -> Exception (27208.0)

発生した例外を返します。

...eError :raise イベントのためのイベントフックの外側で実行し
た場合に発生します。

//emlist[例][ruby]{
trace = TracePoint.new(:raise) do |tp|
tp.raised_exception # => #<ZeroDivisionError: divided by 0>
end
trace.enable
begin
0/0
rescue
end
//}...

TracePoint#inspect -> String (27120.0)

self の状態を人間に読みやすい文字列にして返します。

...self の状態を人間に読みやすい文字列にして返します。

//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:call) do |tp|
p
tp.inspect # "#<TracePoint:call `foo'@/path/to/test.rb:1>"
end
trace.enable
foo 1
//}...

TracePoint#eval_script -> String | nil (27114.0)

script_compiledイベント発生時にコンパイルされたソースコードを返します。 ファイルから読み込んだ場合は、nilを返します。

...script_compiledイベント発生時にコンパイルされたソースコードを返します。
ファイルから読み込んだ場合は、nilを返します。

//emlist[例][ruby]{
TracePoint
.new(:script_compiled) do |tp|
p
tp.eval_script # => "puts 'hello'"
end.enable do
eval("puts 'he...
...llo'")
end
//}

@raise RuntimeError :script_compiled イベントのための
イベントフックの外側で実行した場合に発生します。...

TracePoint#parameters -> [object] (27114.0)

現在のフックが属するメソッドまたはブロックのパラメータ定義を返します。 フォーマットは Method#parameters と同じです。

...parameters と同じです。

@raise RuntimeError :call、:return、:b_call、:b_return、:c_call、:c_return
イベントのためのイベントフックの外側で実行した場合に発生します。

//emlist[例][ruby]{
def foo(a, b = 2)
end
TracePoint
.new(:call) do |tp...
...|
p
tp.parameters # => a], [:opt, :b
end.enable do
foo(1)
end
//}

@see Method#parameters, UnboundMethod#parameters, Proc#parameters...

絞り込み条件を変える

TracePoint#path -> String (27114.0)

イベントが発生したファイルのパスを返します。

...トが発生したファイルのパスを返します。

@raise RuntimeError イベントフックの外側で実行した場合に発生します。

//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:call) do |tp|
p
tp.path # => "/path/to/test.rb"
end
trace.enable
foo 1
//}...

TracePoint.new(*events) {|obj| ... } -> TracePoint (24283.0)

新しい TracePoint オブジェクトを作成して返します。トレースを有効 にするには TracePoint#enable を実行してください。

...しい TracePoint オブジェクトを作成して返します。トレースを有効
にするには TracePoint#enable を実行してください。

//emlist[例:irb で実行した場合][ruby]{
trace = TracePoint.new(:call) do |tp|
p
[tp.lineno, tp.defined_class, tp.method_id, tp.event]
e...
...nd
# => #<TracePoint:0x007f17372cdb20>

trace.enable
# => false

p
uts "Hello, TracePoint!"
# ...
# [69, IRB::Notifier::AbstractNotifier, :printf, :call]
# ...
//}

トレースを無効にするには TracePoint#disable を実行してください。

//emlist[][ruby]{
trace.disable
//}

@param even...
...メソッドを実行した場合には
RuntimeError が発生します。

//emlist[例][ruby]{
TracePoint
.trace(:line) do |tp|
p
tp.raised_exception
end
# => RuntimeError: 'raised_exception' not supported by this event
//}

イベントフックの外側で、発生したイベントに関連...
...ipt_compiled

スクリプトのコンパイル

指定イベントに関連しない情報を取得するメソッドを実行した場合には
RuntimeError が発生します。

//emlist[例][ruby]{
TracePoint
.trace(:line) do |tp|
p
tp.raised_exception
end
# => RuntimeError: 'raised_except...

TracePoint.trace(*events) {|obj| ... } -> TracePoint (24253.0)

新しい TracePoint オブジェクトを作成して自動的にトレースを開始し ます。TracePoint.new のコンビニエンスメソッドです。

...新しい TracePoint オブジェクトを作成して自動的にトレースを開始し
ます。TracePoint.new のコンビニエンスメソッドです。

@param events トレースするイベントを String か Symbol で任
意の数指定します。指定できる値に...
...ついては
TracePoint
.new を参照してください。

//emlist[例][ruby]{
trace = TracePoint.trace(:call) { |tp| [tp.lineno, tp.event] }
# => #<TracePoint:0x007f786a452448>

trace.enabled? # => true
//}

@raise ThreadError ブロックを指定しなかった場合に発生し...

TracePoint#defined_class -> Class | module (24050.0)

メソッドを定義したクラスかモジュールを返します。

...メソッドを定義したクラスかモジュールを返します。

//emlist[例][ruby]{
class C; def foo; end; end
trace = TracePoint.new(:call) do |tp|
p
tp.defined_class # => C
end.enable do
C.new.foo
end
//}

メソッドがモジュールで定義されていた場合も(include に...
...][ruby]{
module M; def foo; end; end
class C; include M; end;
trace = TracePoint.new(:call) do |tp|
p
tp.defined_class # => M
end.enable do
C.new.foo
end
//}

[注意] 特異メソッドを実行した場合は TracePoint#defined_class は特異クラ
スを返します。また、Kernel.#set_tr...
...く元のクラスを返します。

//emlist[例][ruby]{
class C; def self.foo; end; end
trace = TracePoint.new(:call) do |tp|
p
tp.defined_class # => #<Class:C>
end.enable do
C.foo
end
//}

Kernel.#set_trace_func と TracePoint の上記の差分に注意して
ください。

@see 50864...

TracePoint#disable -> bool (24026.0)

self のトレースを無効にします。

...self のトレースを無効にします。

実行前の TracePoint#enabled? を返します。(トレースが既に有効であっ
た場合は true を返します。そうでなければ false を返します)

//emlist[例][ruby]{
trace.enabled? # => true
trace.disable # => false (実行前...
...true
//}

[注意] イベントフックのためのメソッドに、ブロックの外側で参照した場合は
RuntimeError が発生する事に注意してください。

trace.enable { p trace.lineno }
# => RuntimeError: access from outside

@see TracePoint#enable, TracePoint#enabled?...

絞り込み条件を変える

<< 1 2 3 > >>