method
defined_class
v2_1_10 -
Show latest stable
-
0 notes -
Class: TracePoint
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
defined_class()
public
Return class or module of the method being called.
class C; def foo; end; end trace = TracePoint.new(:call) do |tp| p tp.defined_class #=> C end.enable do C.new.foo end
If method is defined by a module, then that module is returned.
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
Note: #defined_class returns singleton class.
6th block parameter of Kernel#set_trace_func passes original class of attached by singleton class.
This is a difference between Kernel#set_trace_func and TracePoint.
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