tracing variables

G

gabriele renzi

Hi gurus and nubys,

I wonder: is there a way in ruby to trace assignments to variables?
 
P

Paul Brannan

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
 
J

John Carter

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 : (e-mail address removed)
New Zealand

The universe is absolutely plastered with the dashed lines exactly one
space long.
 
G

gabriele renzi

il Tue, 6 Jul 2004 13:43:35 +0900, John Carter
<[email protected]> ha scritto::

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top