Class: TracePoint
Overview
You can’t subclass Binding, so we delegate (which is better anyway).
Constant Summary collapse
- EVENT_MAP =
methods for working with events
{ :all => ['call', 'c-call', 'return', 'c-return', 'line', 'class', 'end', 'raise'], :before => ['call', 'c-call'], :after => ['return', 'c-return'], :call => ['call'], :return => ['return'], :ccall => ['c-call'], :creturn => ['c-return'], :line => ['line'], :class => ['class'], :end => ['end'], :raise => ['raise'] }
- @@active =
false
Instance Attribute Summary collapse
-
#back_binding ⇒ Object
– instance ——————-.
-
#binding ⇒ Object
– instance ——————-.
-
#event ⇒ Object
– instance ——————-.
Class Method Summary collapse
- .active ⇒ Object
- .active=(x) ⇒ Object
-
.trace ⇒ Object
Trace execution using a TracePoint.
Instance Method Summary collapse
-
#===(e) ⇒ Object
For use in case conditions.
-
#back ⇒ Object
shorthand for back_binding.
-
#bind ⇒ Object
shorthand for binding.
-
#called ⇒ Object
(also: #method_name, #me)
Returns the name of the event’s method.
-
#event? ⇒ Boolean
Is the trace point defined or undefined?.
- #event_map(e) ⇒ Object
- #eventless? ⇒ Boolean
-
#initialize(event, method, bind, back_binding = bind) ⇒ TracePoint
constructor
Until Ruby has a built-in way to get the name of the calling method that information must be passed into the TracePoint.
-
#self ⇒ Object
Delegates “self” to the binding which in turn delegates the binding object.
Constructor Details
#initialize(event, method, bind, back_binding = bind) ⇒ TracePoint
Until Ruby has a built-in way to get the name of the calling method that information must be passed into the TracePoint.
79 80 81 82 83 84 |
# File 'lib/carat/tracepoint.rb', line 79 def initialize( event, method, bind, back_binding=bind ) @event = event @method = method @binding = bind @back_binding = back_binding end |
Instance Attribute Details
#back_binding ⇒ Object
– instance ——————-
75 76 77 |
# File 'lib/carat/tracepoint.rb', line 75 def back_binding @back_binding end |
#binding ⇒ Object
– instance ——————-
75 76 77 |
# File 'lib/carat/tracepoint.rb', line 75 def binding @binding end |
#event ⇒ Object
– instance ——————-
75 76 77 |
# File 'lib/carat/tracepoint.rb', line 75 def event @event end |
Class Method Details
.active ⇒ Object
44 |
# File 'lib/carat/tracepoint.rb', line 44 def active ; @@active ; end |
.active=(x) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/carat/tracepoint.rb', line 46 def active=(x) @@active = x ? true : false unless @@active set_trace_func nil end end |
.trace ⇒ Object
Trace execution using a TracePoint.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/carat/tracepoint.rb', line 54 def trace # :yield: if active bb_stack = [] set_trace_func proc{ |e, f, l, m, b, k| #(p e, f, l, m, b, k, @@bb_stack; puts "---") if $DEBUG if ['call','c-call','class'].include?(e) bb_stack << b elsif ['return','c-return','end'].include?(e) bb = bb_stack.pop end b = bb if ! b # this sucks! tp = TracePoint.new(e,m,b,bb) yield(tp) } end end |
Instance Method Details
#===(e) ⇒ Object
For use in case conditions
130 131 132 |
# File 'lib/carat/tracepoint.rb', line 130 def ===(e) EVENT_MAP[e].include?(@event) end |
#back ⇒ Object
shorthand for back_binding
90 |
# File 'lib/carat/tracepoint.rb', line 90 def back ; @back_binding ; end |
#bind ⇒ Object
shorthand for binding
87 |
# File 'lib/carat/tracepoint.rb', line 87 def bind ; @binding ; end |
#called ⇒ Object Also known as: method_name, me
Returns the name of the event’s method. This could delegate to the binding if Ruby had an internal way to retrieve the current method name.
99 |
# File 'lib/carat/tracepoint.rb', line 99 def called ; @method ; end |
#event? ⇒ Boolean
Is the trace point defined or undefined?
126 |
# File 'lib/carat/tracepoint.rb', line 126 def event? ; !! @event ; end |
#event_map(e) ⇒ Object
123 |
# File 'lib/carat/tracepoint.rb', line 123 def event_map(e) ; EVENT_MAP[e] ; end |
#eventless? ⇒ Boolean
127 |
# File 'lib/carat/tracepoint.rb', line 127 def eventless? ; ! @event ; end |
#self ⇒ Object
Delegates “self” to the binding which in turn delegates the binding object.
94 |
# File 'lib/carat/tracepoint.rb', line 94 def self ; @binding.self ; end |