種類
- モジュール関数 (48)
- インスタンスメソッド (24)
- 特異メソッド (24)
- 関数 (12)
クラス
- Thread (12)
- TracePoint (12)
- Tracer (24)
モジュール
- Kernel (48)
キーワード
-
add
_ filter (24) - caller (36)
-
defined
_ class (12)
検索結果
先頭5件
-
static VALUE set
_ trace _ func(VALUE obj , VALUE trace) (38416.0) -
Kernel#set_trace_func の実体。 評価器に対するフック手続きを登録します。
...Kernel#set_trace_func の実体。
評価器に対するフック手続きを登録します。... -
Kernel
. # set _ trace _ func(proc) -> Proc (21113.0) -
Ruby インタプリタのイベントをトレースする Proc オブジェクトとして 指定された proc を登録します。 nil を指定するとトレースがオフになります。
...Ruby インタプリタのイベントをトレースする Proc オブジェクトとして
指定された proc を登録します。 nil を指定するとトレースがオフになります。
Ruby インタプリタがプログラムを実行する過程で、メソッドの呼び出しや......準添付の debug、tracer、
profile はこの組み込み関数を利用して実現されています。
=== ブロックパラメータの意味
渡す Proc オブジェクトのパラメータは
//emlist[][ruby]{
proc{|event, file, line, id, binding, klass| "..." }
//}
で、意味は以下......Class オブジェクト。トップレベルでは nil。
//}
@param proc トレース用 Proc オブジェクトを指定します。nil を指定した場合、トレースをオフにします。
@return proc を返します。
//emlist[例][ruby]{
set_trace_func lambda {|*arg|
p arg
}
clas... -
Thread
# set _ trace _ func(pr) -> Proc | nil (18225.0) -
スレッドにトレース用ハンドラを設定します。
...nil を渡すとトレースを解除します。
設定したハンドラを返します。
//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,......e87cb08>, nil]
# => ["c-call", "example.rb", 2, :inherited, #<Binding: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......c8de88d6b0>, nil]
# => ["line", "example.rb", 4, nil, #<Binding:0x00007fc8de88c440>, 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:0x... -
TracePoint
# defined _ class -> Class | module (6212.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 に関係なく)モジュー
ルを返します。
//emlist[例][ruby]{
module......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_trace_func の 6 番目......クラスではなく元のクラスを返します。
//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 の上記の差分に注意して
ください... -
Kernel
. # caller(range) -> [String] | nil (6106.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...ます。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を返します。
@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得......囲を示す Range オブジェクトを指定します。
@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `foo'", "-:10:in `bar'",......[]
# nil
//}
以下の関数は、caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]... -
Kernel
. # caller(start = 1) -> [String] | nil (6106.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...ます。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を返します。
@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得......囲を示す Range オブジェクトを指定します。
@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `foo'", "-:10:in `bar'",......[]
# nil
//}
以下の関数は、caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]... -
Kernel
. # caller(start , length) -> [String] | nil (6106.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...ます。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を返します。
@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得......囲を示す Range オブジェクトを指定します。
@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations
//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end
def bar
foo
end
bar
#=> ["-:2:in `foo'", "-:10:in `bar'",......[]
# nil
//}
以下の関数は、caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]... -
Tracer
. add _ filter {|event , file , line , id , binding , klass| . . . . } (6106.0) -
トレース出力するかどうかを決定するフィルタを追加します。 何もフィルタを与えない場合はすべての行についてトレース情報が出力されます。 与えられた手続き(ブロックまたはProcオブジェクト)が真を返せば トレースは出力されます。
...ジェクトを指定します。
通常、true か falseを返す必要があります。
フィルタ手続きは引数として event, file, line, id, binding, klass の
6 つをとります。
Kernel.#set_trace_func で指定するものとほぼ同じです。
=== フィルタ手......//emlist{
* line (-) ある行を実行
* call (>) メソッド呼び出し
* return (<) メソッドからのリターン
* class (C) クラスコンテキストに入った
* end (E) クラスコンテキストから出た
* raise 例外が発生した
* c-call C......//}
: file
現在処理しているファイルの名前
: line
現在処理している行番号
: id
最後に呼び出されたメソッドのメソッド名(のシンボル)
そのようなメソッドがなければ0になる。
: binding
現在のコンテキスト
: klass
現... -
Tracer
. add _ filter(proc) (6106.0) -
トレース出力するかどうかを決定するフィルタを追加します。 何もフィルタを与えない場合はすべての行についてトレース情報が出力されます。 与えられた手続き(ブロックまたはProcオブジェクト)が真を返せば トレースは出力されます。
...ジェクトを指定します。
通常、true か falseを返す必要があります。
フィルタ手続きは引数として event, file, line, id, binding, klass の
6 つをとります。
Kernel.#set_trace_func で指定するものとほぼ同じです。
=== フィルタ手......//emlist{
* line (-) ある行を実行
* call (>) メソッド呼び出し
* return (<) メソッドからのリターン
* class (C) クラスコンテキストに入った
* end (E) クラスコンテキストから出た
* raise 例外が発生した
* c-call C......//}
: file
現在処理しているファイルの名前
: line
現在処理している行番号
: id
最後に呼び出されたメソッドのメソッド名(のシンボル)
そのようなメソッドがなければ0になる。
: binding
現在のコンテキスト
: klass
現...