るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Kernel.#set_trace_func(proc) -> Proc (18143.0)

Ruby インタプリタのイベントをトレースする Proc オブジェクトとして 指定された proc を登録します。 nil を指定するとトレースがオフになります。

...たメソッド呼び出しからのリターン。
"class": クラス定義、特異クラス定義、モジュール定義への突入。
"end": クラス定義、特異クラス定義、モジュール定義の終了。
"raise": 例外の発生。
//}
: file
実行中のプ...
...は nil。
call/return/c-call/c-return
呼び出された/リターンするメソッドを表す Symbol オブジェクト。
class/end
nil。
raise
最後に呼び出されたメソッドを表す Symbol オブジェクト。
トップレベルでは nil...
...レースをオフにします。

@return proc を返します。

//emlist[例][ruby]{
set_trace_func
lambda {|*arg|
p arg
}
class Foo
end

43.to_s

# ----結果----
# ["c-return", "..", 1, :set_trace_func, #<Binding:0xf6ceb8>, Kernel]
# ["line", "..", 4, nil, #<Binding:0x10cbcd8>, nil]
# ["c-cal...

Thread#set_trace_func(pr) -> Proc | nil (18143.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]
# =>...
..., "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:0x00007fc8de88c440>, nil]
# => ["c-call",...
..."c-return", "example.rb", 5, :current, #<Binding:0x00007fc8de9673b0>, Thread]
# => ["c-call", "example.rb", 5, :set_trace_func, #<Binding:0x00007fc8de966fc8>, Thread]
//}

@param pr トレースハンドラ(Proc オブジェクト) もしくは nil
@see Thread#add_trace_func Kernel.#set_trace_func...

TracePoint#defined_class -> Class | module (90.0)

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

...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 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_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 の上記の差分に注意して
ください。

@see 50864...

ruby 1.8.4 feature (84.0)

ruby 1.8.4 feature ruby 1.8.4 での ruby 1.8.3 からの変更点です。

...eature/組み込みライブラリ>))
* ((<ruby 1.8.4 feature/UnboundMethod#bind [bug]>))
* ((<ruby 1.8.4 feature/set_trace_func [bug]>))
* ((<ruby 1.8.4 feature/set_trace_func [change]>))
* ((<ruby 1.8.4 feature/printf [bug]>))
* ((<ruby 1.8.4 feature/Hash [bug]>))
* ((<ruby 1.8.4 featu...
...適合する文字列を厳密にした。((<ruby-core:03573>)),((<ruby-dev:27478>))

1) alias :"foo" :"bar"

def bar; p "bar"; end
alias :"foo" :"bar"
foo

# => ruby 1.8.4 (2005-12-22) [i686-linux]
-:2: syntax error, unexpecte...
..."$- "
2631438

# => ruby 1.8.4 (2005-12-22) [i686-linux]
-:2: syntax error, unexpected '(', expecting $end

#Tue Nov 1 14:20:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
#
# * eval.c (rb_call_super): should call method_missing if super is
#...

Kernel.#caller(range) -> [String] | nil (48.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...ange オブジェクトを指定します。

@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'", "-:13:in `<mai...
...+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end

end


def foo
p parse_caller(caller.first)
end


def bar
foo
p parse_caller(caller.first)
end


bar
p parse_caller(caller.first)

#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}

以下は...
...、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。

//emlist[例][ruby]{
$DEBUG = true

def debug(*args)
p [caller.first, *args] if $DEBUG
end


debug "debug information"

#=> ["-:7", "debug information"]
//}...

絞り込み条件を変える

Kernel.#caller(start = 1) -> [String] | nil (48.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...ange オブジェクトを指定します。

@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'", "-:13:in `<mai...
...+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end

end


def foo
p parse_caller(caller.first)
end


def bar
foo
p parse_caller(caller.first)
end


bar
p parse_caller(caller.first)

#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}

以下は...
...、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。

//emlist[例][ruby]{
$DEBUG = true

def debug(*args)
p [caller.first, *args] if $DEBUG
end


debug "debug information"

#=> ["-:7", "debug information"]
//}...

Kernel.#caller(start, length) -> [String] | nil (48.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...ange オブジェクトを指定します。

@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'", "-:13:in `<mai...
...+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end

end


def foo
p parse_caller(caller.first)
end


def bar
foo
p parse_caller(caller.first)
end


bar
p parse_caller(caller.first)

#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}

以下は...
...、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。

//emlist[例][ruby]{
$DEBUG = true

def debug(*args)
p [caller.first, *args] if $DEBUG
end


debug "debug information"

#=> ["-:7", "debug information"]
//}...

Thread#add_trace_func(pr) -> Proc (30.0)

スレッドにトレース用ハンドラを追加します。

...ドラを返します。

@param pr トレースハンドラ(Proc オブジェクト)

//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: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...

tracer (24.0)

実行トレース出力をとる機能を提供します。

...class Hoge
def Hoge.fuga(i)
"fuga #{i}"
end

end


Tracer.add_filter {|event, file, line, id, binding, klass|
event =~ /line/ and klass.to_s =~ /hoge/i
}
Tracer.on
for i in 0..3
puts Hoge.fuga(i) if i % 3 == 0
end

Tracer.off

=== SEE ALSO

Kernel.#set_trace_func...
<< 1 2 > >>