> > 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.

I guess what I'm trying to do is similar.  Just as you're trying to catch 
updates to fields in order to automagically update GUI elements, I'm 
(effectively) trying to catch instance variable creation, so that I can 
coerce the value being stored so that it's an object of a different type, 
that makes a reference to the original.

What I'm trying to create is a simple database for applications that don't 
require a full-blown one.  The most important thing is that it be completely 
transparent to the user.

> since = is not a method you can't redefine it in any way, nor callback
> on it.

True, but just as Module has method_added(), which is called whenever a new 
method is added to the module, I don't see why there could not be an 
instance_added() for Class or Object or Kernel that was called whenever an 
instance was added to any class.

> 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.

Yep. The issue is that in order to get the level of transparency I'd like to 
achieve, I don't want the user to have to write any code.

I thought I might be able to maybe write my own versions of attr_writer and 
attr_accessor that created a special version of field=() that included the 
processing I want, but the following example shows that won't work.

    class Fred
       def a=(a)
           $stderr.puts "Setting @a to #{a}"
           @a = a
       end

       def initialize(a)
           @a = a
       end
   end

   f = Fred.new(123)

   f.a = 456

When you run this, it prints "Setting @a to 456".  The initial setting of @a 
in initialize doesn't get caught.  Ie, a=() doesn't seem to come into effect 
until AFTER the instance variable has been created.

> 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.

My sentiments, exactly.  Of course, I realise there are limits to what can be 
achieved ... but I wish the limits were just past everything I'd like to do, 
rather than just this side :-).