From: Richard Dale Date: 2003-07-15T22:37:29+09:00 Subject: Re: Custom method_missing doesn't trap super call Brian Candler wrote: > On Tue, Jul 15, 2003 at 07:36:13PM +0900, Richard Dale wrote: >> >> It looks like you have reinvented the delegator pattern: >> >> http://www.rubycentral.com/book/lib_patterns.html >> >> >> >> Cheers, >> >> >> >> Brian. >> >> >> >> >> > >> > Well crap, wouldn't you know... I guess I need to do some more >> > exploring through Ruby resources. >> But thanks - I'll experiment with the delegator suggestions - I think >> this is a fun problem to try and solve somehow.. > > Absolutely. I kind of "discovered" delegation too, and found it gives you > a great way to build objects out of components - much more flexible than > subclassing, and neatly sidesteps a lot of philosophical issues with > subclassing too. I just tried adding this onto the end of the Example 2 of delegation in Programming Ruby (page 468): class FooBar < TicketOffice def try_delegate_to_super() puts "In try_delegate_to_super" super end end to = FooBar.new puts to.sellTicket to.try_delegate_to_super So the superclass of FooBar is a delegator. When I ran it I got the following output: ruby trydelegate2.rb Here is a ticket In try_delegate_to_super trydelegate2.rb:33:in `try_delegate_to_super': super: no superclass method `try_delegate_to_super' (NameError) from trydelegate2.rb:39 So although the SimpleDelegate class doesn't use method_missing (my ruby isn't good enough to tell how it works yet), it isn't possible to forward a message to super this way either. -- Richard