From: Victor Shepelev Date: 2006-05-11T08:49:09+09:00 Subject: Re: Module#add_tracer From: Logan Capaldo [mailto:logancapaldo@gmail.com] > On May 10, 2006, at 7:34 PM, Victor Shepelev wrote: > > From: Logan Capaldo [mailto:logancapaldo@gmail.com] > >> On May 10, 2006, at 6:45 PM, Victor Shepelev wrote: > >>> class Module > >>> def add_tracer(meth) > >>> m_alias = case meth > >>> when :[] : "old_idx" > >>> when :+ : "old_plus" > >>> when :- : "old_minus" > >>> #and so on > >>> else ; "old_#{meth}" > >>> end > >>> module_eval %Q{ > >>> alias :#{m_alias} :#{meth} > >>> def #{meth}(*arg, &block) > >>> puts caller[0] + ": " + self.class.name + "##{meth} called" > >>> #{m_alias}(*arg, &block) > >>> end > >>> } > >>> end > >>> end > >> -------------------------------------------------- > >> Kernel#set_trace_func > >> set_trace_func(proc) => proc > >> set_trace_func(nil) => nil > >> --------------------------------------------------------------------- > >> --- > >> Establishes proc as the handler for tracing, or disables > >> tracing > >> if the parameter is nil. proc takes up to six parameters: an > >> event > > > > Of cause I know about this. My solution is much more lightweight > > (because > > only one function of one class would be slow down). > > > > Victor. > > > > > > Yours also breaks when someone else overrides the same method and > aliases it to old_#{meth} (Which, unfortunately is pretty common.) Yeah. It also breaks in dosens of other cases :) I've just show and idea. But you're quite right. Maybe I must say something like untraced_#{meth} V