From: Tom Sawyer Date: 2002-08-04T21:49:32+09:00 Subject: Re: Detecting when an instance variable is created/set On Sun, 2002-08-04 at 06:03, Harry Ohlsen wrote: > Imagine we have a class like ... > > class Fred > def initialize(a, b) > @a = a > @b = b > end > end > > Can I write a method (of class Object or Kernel, perhaps) that will be called > when the "@a = a" occurs? What I'm looking for would be something like ... > > def instance_var_created(c, name, value) > $stderr.puts "@#{name} of class #{c.class} set to #{value}" > end > > Is this possible? this has been touched on in some of the other threads. i brought it up myself in relation to "automagical" gui bindings. anyway, the short answer appears to be NO. since = is not a method you can't redefine it in any way, nor callback on it. i don't know what your attempting to do, but if you create accessor methods: def a=(x) @a = x end then of course you can get at those. but that may not be what you want. at this point i wish to SPEAK UP and say once again, i would prefer that EVERYTHING were OO. i choose ruby over python for this very reason! (although i like ruby over python despite that now anyway). alas not even ruby is pure. ~transami > > -- ~transami