From: "T. Onoma" Date: 2003-12-08T03:50:22+09:00 Subject: Re: Underpinnings of Method Wrapping Here is an intereseting problem that I'm currently facing and which is related to method wrapping. I have a superclass called Recipe which has functionality for compiling and installing programs from source. I create "specialty" recipes by subclassing this. In a subclass I define the compile method to handle the details of compiling but all of the compiling must be "wrapped" in a chroot environment setup by routines in the superclass. How do I generically wrap the subclass method from the superclass? Here's a basic example of the NON-GENERIC way to do it, to help explain: class Recipe def construct_chroot ... end def deconstruct_chroot ... end end class SpecialRecipe < Recipe def compile construct_chroot() ... # special compile code deconstruct_chroot() end end The problem with the above is that I do not wish for the subclass to have to explictly call the construct and deconstruct methods. It needs to be GENERIC, b/c if these calls were accidently forgotten it could potentially damage the root file system. As always, I may be over looking the obvious. But if anyone has a current workable solution I would be most grateful. --- For those interested in method wrapping prorposals this has some interesting solutions. First there is "shrink wrapping" i.e. super-wrapping: class Recipe def construct_chroot ... end def deconstruct_chroot ... end def compile construct_chroot() super # must work like: super if defined?(super) deconstruct_chroot() end end class SpecialRecipe < Recipe def compile superwrap ... # special compile code super ... # and/or special compile code end end end Secondly, It is a perfect example of *outer wraps* -- wraps that remain intact even when the primary method is redefined (opposed to *inner wraps* which do not) class Recipe def construct_chroot ... end def deconstruct_chroot ... end def compile ... end def:outerwrap compile construct_chroot super deconstruct_chroot end end class SpecialRecipe < Recipe def compile ... # special compile code end end Interseting stuff! T.