-----Original Message-----
From: Robert Klemme [mailto:shortcutter / googlemail.com]=20
Sent: 21 October 2011 12:33
To: ruby-talk ML
Subject: Re: wrapping object and method_missing

On Thu, Oct 20, 2011 at 7:04 PM, James French
<James.French / naturalmotion.com> wrote:
>
>
> -----Original Message-----
> From: Hans Mackowiak [mailto:hanmac / gmx.de]
> Sent: 20 October 2011 18:02
> To: ruby-talk ML
> Subject: Re: wrapping object and method_missing
>
> there:
>
> class Wrapper
> =A0def method_missing(meth,*args)
> =A0 =A0return @obj.send(meth,*args)
> =A0end
> end
>
> --
> Posted via http://www.ruby-forum.com/.
>
> Thanks but I wanted to put the code in the wrapped object so it automatic=
ally intercepts method_missing in Wrapper.

This cannot work unless the wrapped knows who is wrapping it.  And
normally (i.e. when setting a member of any other object to reference
your object) your object wouldn't know when it was wrapped.

Also, it's a questionable design because you introduce a bidirectional
dependency.  Also, what do you do in case of multiple wrappers or
changing wrappers?

What is it that you really want to solve?



I'm fine with the wrapped object knowing about the wrapper, and agree its n=
ecessary. I may not end up using this but I just wanted to know how to do i=
t in ruby. All I'm trying to achieve is a clean interface. If there's no ot=
her way I'll just have a wrapper base class that implements method_missing =
and delegates to internal object.

Cheers for the help.