From: Robert Klemme Date: 2004-07-26T17:16:57+09:00 Subject: Re: delegate also from the inside "Florian Weber" schrieb im Newsbeitrag news:A65539F2-DE25-11D8-8F52-000A95BD142E@structbench.com... > > On Jul 24, 2004, at 19:26 Uhr, Robert Klemme wrote: > > > > > "Florian Weber" schrieb im Newsbeitrag > > news:6F425BDB-DCFB-11D8-9B88-000A95BD142E@structbench.com... > >> hi! > >> > >> if i use a proxy to wrap a object, is there a way to allow that calls > >> from the wrapped object to a method in the wrapped object go via > >> the proxy. > >> > >> example: > >> > >> proxy#foo calls object#foo calls proxy#bar calls object#bar > >> > >> instead of > >> > >> proxy#foo calls object#foo calls object#bar > > > > No way other than modifying the wrapped instance. The wrapper knows > > the > > wrapped instance but not the other way round. You might consider using > > inheritance in this case - if that works in your scenario. Or use a > > completely different strategy. > > what ways via modifications would work? besides using inheritance? Overriding methods in the instance to wrap. You could do that automatically to move every method to xyz_unwrapped and subsitute it with def xyz; wrapper.xyz; end while the wrapper invokes always wrapped.xyz_unwrapped(). Quite complicated though. Or you write the class to be wrapped from the start to take wrapping into account if that's possible. Something like class Wrappable attr_accessor :wrapper def me; wrapper or self; end def some_method me.some_other_method end def some_other_method # ... end end Other than that I'd have to know the scenario in order to come up with additional suggestions. I guess these solutions then would not make use of wrapping. :-) Kind regards robert