On 16 Mai, 21:17, "Adriano Ferreira" <a.r.ferre... / gmail.com> wrote:
> On 5/16/07, edl... / gmail.com <edl... / gmail.com> wrote:
>
> > 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?
>
> As Stefano said, you can modify the methods of a class in Ruby anytime you want.
>
> irb> class Foo
> irb>    attr_accessor :foo # here the conventional accessor is defined
> irb>
> irb*    def foo # and here it is overriden
> irb>        puts "foo invoked"
> irb>        @foo
> irb>    end
> irb> end
> => nil
>
> irb> Foo.new.foo
> foo invoked
> => nil

Unfortunately this is not at runtime. The original class must be
untouched.
But there have been some postings before in this thread that showed
how to do this at runtime.
The method module_eval was a cool hint.

But thanks anyway!
Best
Stefan Edlich