From: Jim Cain Date: 2003-07-15T15:01:10+09:00 Subject: Re: Custom method_missing doesn't trap super call Yukihiro Matsumoto wrote: > In message "Re: Custom method_missing doesn't trap super call" > on 03/07/15, Richard Dale writes: > > |Perhaps I should explain more what about I was trying to do - I didn't want > |to over complicate the problem description. I'm working on bindings to a > |C++ gui library Qt, and use a C method_missing (in the C 'Qt' extension) to > |forward the calls to the C++ methods from ruby. When virtual methods are > |overriden in ruby, like QPushButton::paintEvent(), it uses rb_respond_to() > |to see whether or not there is a ruby version of the method. > > I understand what you want. But why use method_missing? If Qt has > finite set of methods, why don't you define wrapper methods just as > Swig does? > > This does not mean I'm refusing "method_missing for super". I'm still > thinking. > > matz. > > I just had occasion to invent a solution for this in something I was working on. Unfortunately, I wasn't paying enough attention to this thread beforehand, so I don't know if someone has already recommended a solution similar to mine--or even worse, recommended against it. :) My goal is to wrap the instance variable @obj so that, from the outside of the Wrapper object, it responds exactly like the @obj would. ---------8<--------- class Wrapper # don't respond to any inherited public methods (methods - ['__id__', '__send__']).each do |meth| begin undef_method meth.intern rescue # ignore end end def initialize(conn, klass, id) @obj = ... end def method_missing(meth, *args) @obj.__send__(meth, *args) end ---------8<--------- Comments?