From: Alexander Schofield Date: 2001-12-18T10:13:03+09:00 Subject: [ruby-talk:28825] Re: Tracing instance variables Paul Brannan wrote: > > On Tue, Dec 18, 2001 at 01:51:16AM +0900, Jason Voegele wrote: > > Is there a better way to do this? I know that global variables can be > > traced for modification. Is there some way to trace instance variables as > > well, either in standard Ruby or any existing library? I'm already using > > AspectR for the binding, but I don't think it supports tracing instance > > variables. > > You can trace assignments to global variables, but you cannot trace > modifications of globals. E.g.: > > trace_var :$foo, proc { |x| p x } > $foo = "foo" > $foo.sub!('f', 'b') > > will print "foo" when the assignment is made, but will not print "boo" > when the modification is done. > > Paul attr_accessor creates = methods for it's instance vars. Could you use set_trace_func with a proc to intercept those method calls? Of course to keep track of everything you'd probably need some sort of table of what objects to track, which method calls for each object, and what procs to call for each. TIA, Alexander Schofield