------art_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  # => "something singleton"

whereas still maintaining

C.new(9).var # => 9

On 5/17/07, Stefano Crocco <stefano.crocco / alice.it> wrote:
>
> Alle mercoled16 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 = value
> end
> end
>
> c = C.new 3
> puts c.var
> =>3
>
> C.module_eval{def var; return 2;end}
> c.var => 2
>
> I hope this helps
>
> Stefano
>
>


-- 
sur

------art_14744_7651516.1179342920741--