# Variable Assignment Callback(s)?

**URL:** <https://www.ruby-forum.com/t/variable-assignment-callback-s/60518>\
**Category:** Ruby\
**Created:** [May 15, 2006, 7:41am UTC](https://www.ruby-forum.com/t/variable-assignment-callback-s/60518 "2006-05-15T07:41:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jake\_McArthur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f19dbf/32.png) [@Jake\_McArthur](https://www.ruby-forum.com/u/Jake_McArthur)\
**Post date:** [May 15, 2006, 7:41am UTC](https://www.ruby-forum.com/t/variable-assignment-callback-s/60518/1 "2006-05-15T07:41:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jake\_McArthur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f19dbf/32.png) [@Jake\_McArthur](https://www.ruby-forum.com/u/Jake_McArthur)\
**Post date:** [May 16, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/variable-assignment-callback-s/60518/2 "2006-05-16T17:20:15Z")

</div>

2006/5/15, Jake McArthur [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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
