Hi gurus and nubys,
I wonder: is there a way in ruby to trace assignments to variables?
Hi gurus and nubys,
I wonder: is there a way in ruby to trace assignments to variables?
I don't know of any way, but I think it would be a nice feature to have.
The debugger supports watchpoints, but afaict they seem to only break
when an expression becomes true.
It shouldn't be difficult (though it would be slow) to use
set_trace_func to determine when the value of an expression/variable
changes, but there's no easy way to detect "a = a".
If you want to use this in a real program and not just for debugging,
then you might want to consider using the observer pattern (see
observer.rb).
Paul
On Tue, Jul 06, 2004 at 12:57:39AM +0900, gabriele renzi wrote:
Hi gurus and nubys,
I wonder: is there a way in ruby to trace assignments to variables?
Umm, what exactly do you mean. $globals? Ruby magic variables like $:?
Local variables?
John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand
The universe is absolutely plastered with the dashed lines exactly one
space long.
On Tue, 6 Jul 2004, gabriele renzi wrote:
I wonder: is there a way in ruby to trace assignments to variables?
paul, john, I'll try to answer both in one message.
Actually I don't realy feel the need for this feature, I just happened
to read this:
http://lambda-the-ultimate.org/node/view/58#comment
And I realized that I did not knew if this was possible to do in ruby,
so I asked on the list 
# further delirium
I think this could be an interesting feature, for debugging purposes
and (maybe) to satisfy people that wants stricter checks (i.e. we
could provide required variable declarations like perl strict, or
checking attributes of the objects being assigned to variable.
We could provide first-win behaviour where a progtram could raise an
exception whenever a global variable (even instance and locals,
anyway) got its value changed from the existing type to an
incompatible one due to an error (please don't think type==class) and
other little nifty things.
il Tue, 6 Jul 2004 13:43:35 +0900, John Carter <john.carter@tait.co.nz> ha scritto::