Ruby 编程/标准库/Tracer
外观
< Ruby 编程
Ruby 内置的“tracer.rb”文件以按方法的方式显示调用了哪些行。要使用它
ruby -rtracer script_name.rb
例如,以下代码
class A
def setup
@instvar = 1
end
def go
var = 2
4.times do |@instvar|
@instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font>
end
end
instance = A.new
instance.setup
instance.go
产生如下结果
C:\dev\digitalarchive_trunk>ruby -rtracer test.rb #0:test.rb:1::-: class A #0:test.rb:1:Class:>: class A #0:test.rb:1:Class:<: class A #0:test.rb:1::C: class A #0:test.rb:2::-: def setup #0:test.rb:2:Module:>: def setup #0:test.rb:2:Module:<: def setup #0:test.rb:5::-: def go #0:test.rb:5:Module:>: def go #0:test.rb:5:Module:<: def go #0:test.rb:1::E: class A #0:test.rb:11::-: instance = A.new #0:test.rb:11:Class:>: instance = A.new #0:test.rb:11:Object:>: instance = A.new #0:test.rb:11:Object:<: instance = A.new #0:test.rb:11:Class:<: instance = A.new #0:test.rb:12::-: instance.setup #0:test.rb:2:A:>: def setup #0:test.rb:3:A:-: @instvar = 1` #0:test.rb:4:A:<: end` #0:test.rb:13::-: instance.go #0:test.rb:5:A:>: def go #0:test.rb:6:A:-: var = 2 #0:test.rb:7:A:-: 4.times do |@instvar| #0:test.rb:7:Integer:>: 4.times do |@instvar| #0:test.rb:8:A:-: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:Fixnum:>: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:Fixnum:<: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:A:-: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:Fixnum:>: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:Fixnum:<: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:A:-: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:Fixnum:>: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:Fixnum:<: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:A:-: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:Fixnum:>: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:8:Fixnum:<: @instvar=@instvar*var end # <font color="#007700">#=>0,2,4,6 last assignment of @instvar is 6</font> #0:test.rb:7:Integer:<: 4.times do |@instvar| #0:test.rb:6:A:<: var = 2