On Thursday 29 December 2005 10:08 am, Steve Litt wrote:

> OK, let me see if I'm correctly understanding you.

Yep!

> what really happens is that the function attr_accessor() takes symbol
> :wilbur as an argument, tacks on a @ to the string's value in order to make
> the true class variable @wilbur, and then writes a tiny get and set
> functions whose names are wilbur, such that:
>
> my_object.wilbur = 22
> puts my_object.wilbur
>
> So my initial comment that it seemed like magic is true only to the extent
> that the "magic" performed by attr_accessor is to create the set and get
> methods with the same name as the symbol that is its argument.
>
> Do I understand what you're saying?

That is exactly what happens.

And because that is what happens, one can write attr_accessor-like methods 
oneself, if there is something additional/different that you want to have 
happen.  The symbol is just a tool.


Kirk Haines