Method: TracePoint#enable
- Defined in:
- vm_trace.c
#enable ⇒ Object
trace.enable -> true or false trace.enable { block } -> obj
Activates the trace
Return true if trace was enabled. Return false if trace was disabled.
trace.enabled? #=> false trace.enable #=> false (previous state)
# trace is enabled
trace.enabled? #=> true trace.enable #=> true (previous state)
# trace is still enabled
If a block is given, the trace will only be enabled within the scope of the block.
trace.enabled? #=> false
trace.enable do
trace.enabled?
# only enabled for this block
end
trace.enabled? #=> false
Note: You cannot access event hooks within the block.
trace.enable { p tp.lineno } #=> RuntimeError: access from outside
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 |
# File 'vm_trace.c', line 1077
static VALUE
tracepoint_enable_m(VALUE tpval)
{
rb_tp_t *tp = tpptr(tpval);
int previous_tracing = tp->tracing;
rb_tracepoint_enable(tpval);
if (rb_block_given_p()) {
return rb_ensure(rb_yield, Qnil,
previous_tracing ? rb_tracepoint_enable : rb_tracepoint_disable,
tpval);
}
else {
return previous_tracing ? Qtrue : Qfalse;
}
}
|