Forum: Ruby Variable Assignment Callback(s)?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
49ab3ce5a4922b4747d1d6f330784629?d=identicon&s=25 Jake McArthur (Guest)
on 2006-05-15 07:41
(Received via mailing list)
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 Talk 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
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2006-05-16 17:20
(Received via mailing list)
2006/5/15, Jake McArthur <jake.mcarthur@gmail.com>:
> 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 Talk 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
This topic is locked and can not be replied to.