T. Onoma
10/4/2004 3:10:00 PM
On Monday 04 October 2004 09:13 am, Paul Brannan wrote:
> On Fri, Oct 01, 2004 at 12:44:47PM +0900, trans. (T. Onoma) wrote:
> > How can I subclass the Binding class?
>
> What do you hope to accomplish by doing this?
Short answer:
class TracePoint #< Binding
def initialize(event, binding, back_binding=nil)
@event = event
@binding = binding # delegate!!!
@back_binding = (back_binding ? back_binding : binding)
end
# ...
def self.trace(&yld)
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,b,bb)
yld.call(tp)
}
end
end
T.