From: Stu Date: 2012-11-28T06:06:53+09:00 Subject: Re: Novice: Understanding instance 'variables' and methods --485b390f7deaa794c104cf806d59 Content-Type: text/plain; charset=ISO-8859-1 attr methods actually do the creation, probably with convert to string append the '@' sigil in front and run it through eval, of what symbol was given to them. If you need a quick conceptual open up irb and type: puts '@' + :verb.to_s look into define_method, as well as other eval family methods. Getter/Setters are simple syntax sugar as ruby allows the method name to have '=' so we don't have to type get_verb or set_verb( val). attr is a unique piece of automation for the common templating, boiler plate code, you see in object oriented languages. attr_accesor is a method which creates methods. It wouldn't be as obvious if we where able to actually send the sigilled version of what's being created instead of a symbol. attr_writer( @foo, @bar) would be a bit more obvious. But that won't work as @foo is just a variable and one that is not set. It would actually send the value nil and not the name which is why using a symbol or string does. --485b390f7deaa794c104cf806d59 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable attr methods actually do the creation, probably with convert to string appe= nd the '@' sigil in front and run it through eval, of what symbol w= as given to them.

If you need a quick conceptual open up irb and typ= e:

=A0puts '@' + :verb.to_s

look into define_method, as wel= l as other eval family methods. Getter/Setters are simple syntax sugar as r= uby allows the method name to have '=3D' so we don't have to ty= pe get_verb or set_verb( val). attr is a unique piece of automation for the= common templating, boiler plate code, you see in object oriented languages= .

attr_accesor is a method which creates methods. It wouldn't be as o= bvious if we where able to actually send the sigilled version of what's= being created instead of a symbol. attr_writer( @foo, @bar) would be a bit= more obvious. But that won't work as @foo is just a variable and one t= hat is not set. It would actually send the value nil and not the name which= is why using a symbol or string does.
--485b390f7deaa794c104cf806d59--