class User
def some_method
puts "some method"
end
end
set_trace_func proc { |event, file, line, id, binding, classname|
printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
}
user = User.new
user.some_method
#=>
c-return test.rb:9 set_trace_func Kernel
line test.rb:11
c-call test.rb:11 new Class
c-call test.rb:11 initialize BasicObject
c-return test.rb:11 initialize BasicObject
c-return test.rb:11 new Class
line test.rb:12
call test.rb:2 some_method User
line test.rb:3 some_method User
c-call test.rb:3 puts Kernel
c-call test.rb:3 puts IO
c-call test.rb:3 write IO
some methodc-return test.rb:3 write IO
c-call test.rb:3 write IO
c-return test.rb:3 write IO
c-return test.rb:3 puts IO
c-return test.rb:3 puts Kernel
return test.rb:4 some_method User
您可以更改PROC打印有關用戶的方法僅供參考。
如何添加其他方法?你會再次編輯新的方法嗎? – megas 2012-07-31 21:53:36
你想解決什麼問題? – AJcodez 2012-07-31 22:25:22
我正在嘗試生成一個不顯眼的方法來生成方法回調(在某種方法之前/之後運行某些方法) – rogeliog 2012-08-01 14:25:38