John Wells
3/20/2009 4:43:00 PM
On Fri, Mar 20, 2009 at 12:22 PM, Robert Klemme
<shortcutter@googlemail.com> 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|
>> =A0 n.class_eval do |clz|
>> =A0 =A0 def method_added(x)
>> =A0 =A0 =A0 puts "Method=3D=3D#{x}"
>> =A0 =A0 end
>> =A0 end
>> =A0end
>>
>>
>> And then call
>>
>> $ ruby -rtrace.rb -e 'puts "test"'
>>
>> I only see two "Method=3D=3D" outputted...both "Method=3D=3Dmethod_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.