From: Richard Dale Date: 2003-07-15T05:12:21+09:00 Subject: Re: Custom method_missing doesn't trap super call Yukihiro Matsumoto wrote: > Hi, > > In message "Custom method_missing doesn't trap super call" > on 03/07/15, Richard Dale writes: > > |The non existent call to 't.baz()' is trapped ok. But in MyClass.foobar() > |the 'super' call gives a 'no superclass method' error rather than calling > |Base.method_missing as I expected. Does anyone know if there a way of > |trapping the super call? > > I feel like it's a bad idea in general, but without any particular > reason. Let me think. 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. if (rb_respond_to(obj, rb_intern(methodName)) == 0) { return false; } .... Otherwise if rb_respond_to() returns true, call ruby methods like 'paintEvent' below via rb_funcall2() Then the call to 'super' needs to correctly invoke the C++ paintEvent() method via the method_missing trap. require 'Qt'; class MyClass < Qt::PushButton def paintEvent(event) printf("In paintEvent...\n") super end end a = Qt::Application.new(ARGV, ref nil); hello = MyClass.new("Hello World", nil) hello.resize(100, 30) a.setMainWidget(hello) hello.show() a.exec() > |Thanks for any help - I've just started with ruby - the syntax is really > |nice and 'tidy' (ie un-C++ like :) ) The only other thing I got stuck > |with is how to remove an item from a hash via C. > > Use rb_hash_delete(hash, key); Ah.. thanks thats ideal - I couldn't find it in intern.h with the other rb_hash functions, so I assumed it didn't exist. -- Richard