From: James French Date: 2011-10-21T21:04:10+09:00 Subject: Re: wrapping object and method_missing -----Original Message----- From: Robert Klemme [mailto:shortcutter@googlemail.com] 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 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 >  def method_missing(meth,*args) >    return @obj.send(meth,*args) >  end > end > > -- > Posted via http://www.ruby-forum.com/. > > Thanks but I wanted to put the code in the wrapped object so it automatically 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 necessary. I may not end up using this but I just wanted to know how to do it in ruby. All I'm trying to achieve is a clean interface. If there's no other way I'll just have a wrapper base class that implements method_missing and delegates to internal object. Cheers for the help.