From: John Wells Date: 2009-03-21T01:42:37+09:00 Subject: Re: Tracing method definition in core and stdlibs? On Fri, Mar 20, 2009 at 12:22 PM, Robert Klemme wrote: > On 20.03.2009 13:56, John Wells wrote: >> >> I'm interested in tracing method definition in core and stdlibs. >> However, I'm not sure how to hook in the process at such an early >> stage. >> >> For example, if I put the following code in trace.rb: >> >> [Class, Module].each do |n| >>   n.class_eval do |clz| >>     def method_added(x) >>       puts "Method==#{x}" >>     end >>   end >>  end >> >> >> And then call >> >> $ ruby -rtrace.rb -e 'puts "test"' >> >> I only see two "Method==" outputted...both "Method==method_added", and >> both obviously in response to this code itself. >> >> Is there a way to hook in earlier? > > Probably not as many methods of the standard library are define in C code > and I doubt that will trigger a method_added. > > Btw, what do you need that for? Yes, but I'd expect to see a good bit that were ruby too, correct? I'd like to create a utility method that would allow me to easily see everywhere a method (file name, line number) is defined...I have it working for scripts I write myself, but only going forward from that script scope...not back through the libs. So I'd like to hook in early...before any ruby files are loaded at all.