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.
97 98 99 100 101 102 |
# File 'lib/mega/tracepoint.rb', line 97 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 ——————-
93 94 95 |
# File 'lib/mega/tracepoint.rb', line 93 def back_binding @back_binding end |
#binding ⇒ Object
– instance ——————-
93 94 95 |
# File 'lib/mega/tracepoint.rb', line 93 def binding @binding end |
#event ⇒ Object
– instance ——————-
93 94 95 |
# File 'lib/mega/tracepoint.rb', line 93 def event @event end |
Class Method Details
.active ⇒ Object
62 |
# File 'lib/mega/tracepoint.rb', line 62 def active ; @@active ; end |
.active=(x) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/mega/tracepoint.rb', line 64 def active=(x) @@active = x ? true : false unless @@active set_trace_func nil end end |
.trace ⇒ Object
Trace execution using a TracePoint.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mega/tracepoint.rb', line 72 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
148 149 150 |
# File 'lib/mega/tracepoint.rb', line 148 def ===(e) EVENT_MAP[e].include?(@event) end |
#back ⇒ Object
shorthand for back_binding
108 |
# File 'lib/mega/tracepoint.rb', line 108 def back ; @back_binding ; end |
#bind ⇒ Object
shorthand for binding
105 |
# File 'lib/mega/tracepoint.rb', line 105 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.
117 |
# File 'lib/mega/tracepoint.rb', line 117 def called ; @method ; end |
#event? ⇒ Boolean
Is the trace point defined or undefined?
144 |
# File 'lib/mega/tracepoint.rb', line 144 def event? ; !! @event ; end |
#event_map(e) ⇒ Object
141 |
# File 'lib/mega/tracepoint.rb', line 141 def event_map(e) ; EVENT_MAP[e] ; end |
#eventless? ⇒ Boolean
145 |
# File 'lib/mega/tracepoint.rb', line 145 def eventless? ; ! @event ; end |
#self ⇒ Object
Delegates “self” to the binding which in turn delegates the binding object.
112 |
# File 'lib/mega/tracepoint.rb', line 112 def self ; @binding.self ; end |