Variable Assignment Callback(s)?

I need a callback for variable assignment; instance variable
assignment is the most important, but others would be an even greater
plus. I was searching for a solution and stumbled across this,
apparently from some past Ruby T. thread from before my time here.
I was wondering if any of the potential variable assignment callbacks
besides global scope have been fulfilled? Anybody know?

POTENTIAL ACTUAL

Class creation Class#inherited, AClass#new
Class reopening/closing
Module creation
Module reopening/closing
Method definition Module#method_added
Method removal Module#method_removed
Method undef Module#method_undefined
Singleton-Method definition Object#singleton_method_added
Singleton-method deletion Object#singelton_method_removed
Singleton-method undef Object#singelton_method_undefined
Constant assignment*
Global variable assignment Kernel#trace_var**
Class variable assignment
Instance variable assignment
Local variable assignment
Module inclusion Module::included,
Module#append_features
Module extension Module::extended,
Module#extend_object
Missing Method Object#method_missing
Missing Constant Module#const_missing
Object Destruction ObjectSpace#*_finalizer
Program Termination Kernel#at_exit

  • Constant assignment may encompass class and module creation (?)
    ** Actually a trace rather then a callback
    ++ set_trace_func is not included, it is a separate “universal”
    catch-all
  • Jake McArthur

2006/5/15, Jake McArthur [email protected]:

I need a callback for variable assignment; instance variable
assignment is the most important, but others would be an even greater
plus. I was searching for a solution and stumbled across this,
apparently from some past Ruby T. thread from before my time here.
I was wondering if any of the potential variable assignment callbacks
besides global scope have been fulfilled? Anybody know?

Well, you can test it easily youself can’t you?

Btw, another solution is to change attr_reader, attr and attr_writer
to automatically define methods that will invoke callbacks. If you
then in your code use accessors all the time you’ll get notfied of
assignments pretty easy. But: you won’t see changes in Array and Hash
that way (you probably won’t using instance variable callbacks
either).

Cheers

robert