Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Trace calls in a module

Reply
Thread Tools

Trace calls in a module

 
 
Jonathan Steel
Guest
Posts: n/a
 
      07-23-2010
How do you do the equivalent of include in a module? I would like to
trace all the calls in a module. There is an example for how to do this
as a mixin for a class in the pick axe, but how do I do it for a module?
Can I get access to the meta class for the module and mix it in there?

Thanks
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      07-23-2010
On 07/23/2010 06:33 PM, Jonathan Steel wrote:
> How do you do the equivalent of include in a module? I would like to
> trace all the calls in a module.


I don't understand this: why is tracing of method calls equivalent to
module inclusion?

> There is an example for how to do this
> as a mixin for a class in the pick axe, but how do I do it for a module?
> Can I get access to the meta class for the module and mix it in there?


I don't have my pickaxe handy right now. What does the code do? It may
be possible to just exchange a module with the class.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
 
 
 
Jonathan Steel
Guest
Posts: n/a
 
      07-23-2010
Robert Klemme wrote:
> On 07/23/2010 06:33 PM, Jonathan Steel wrote:
>> How do you do the equivalent of include in a module? I would like to
>> trace all the calls in a module.

>
> I don't understand this: why is tracing of method calls equivalent to
> module inclusion?


The aren't, just what I'm trying to do (below) requires an include,
except I want to use it in a module.

>
>> There is an example for how to do this
>> as a mixin for a class in the pick axe, but how do I do it for a module?
>> Can I get access to the meta class for the module and mix it in there?

>
> I don't have my pickaxe handy right now. What does the code do? It may
> be possible to just exchange a module with the class.
>
> Kind regards
>
> robert


module TraceCalls
def self.included(klass)
klass.instance_methods(false).each do |existing_method|
wrap(klass, existing_method)
end
def klass.method_added(method)
unless @trace_calls_internal
@trace_calls_internal = true
TraceCalls.wrap(self, method)
@trace_calls_internal = false
end
end
def self.wrap(klass, method)
klass.instance_eval do
method_object = instance_method(method)
define_method(method) do |*args, &block|
puts "==> calling #{method} with #{args.inspect}"
result = method_object.bind(self).call(*args, &block)
puts "<== #{method} returned #{result.inspect}"
result
end
end
end
end
end
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding my messages to the trace.axd trace? =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= ASP .Net 3 04-06-2007 06:10 PM
trace.axd and asp.net trace feature IIS only? Jiho Han ASP .Net 0 08-22-2006 12:44 PM
No trace messages using Diagnostics.Trace McGeeky ASP .Net 0 02-01-2006 02:49 PM
How to redirect output from Diagnostics.Trace to Page.Trace? Matthias S. ASP .Net 1 11-30-2005 09:01 AM
Trace: Can anyone suggest a good tool to catch trace messages? Rukmal Fernando ASP .Net 4 10-27-2003 09:03 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57