From: sur max Date: 2007-05-17T04:15:22+09:00 Subject: Re: Some Ruby Features missing... ------=_Part_14744_7651516.1179342920741 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline C.module_eval will modify it for all the objects of class C if something singleton needed for the particular object... then it can be done as def c.var "something singleton" end c.var # =3D> "something singleton" whereas still maintaining C.new(9).var # =3D> 9 On 5/17/07, Stefano Crocco wrote: > > Alle mercoled=EC 16 maggio 2007, edlich@gmail.com ha scritto: > > 2. Can I modify the getter of any instance var?! > > -> E.g. if an attribute defines attr_accessor, can I change the getter > > at > > runtime to do magic aspect stuff around the real get call? > > attr_accessor :var simply defines a method called var which returns the > instance variable @var. You can redefine it as you would with any other > method. > > class C > attr_accessor :var > def initialize value > @var =3D value > end > end > > c =3D C.new 3 > puts c.var > =3D>3 > > C.module_eval{def var; return 2;end} > c.var =3D> 2 > > I hope this helps > > Stefano > > --=20 sur ------=_Part_14744_7651516.1179342920741--