From: retnuh@... (Hunter Kelly) Date: 2004-07-22T02:07:03+09:00 Subject: Re: Skipping an ancestor method Should this take a block, for completeness? H Florian Gross wrote in message news:<2m576aFj3oedU1@uni-berlin.de>... > For the fun of it I've taken this to the extreme and called it > superjump: (It 'jumps' over one or more method in the inheritance chain) > > # Like super this calls methods from the inheritance chain which this > # method is replacing. However this version jumps over one or more > # methods in the inheritance chain. It is used like this: > # > # class X > # def it; p "X#it"; end > # end > # > # class Y < X > # def it; p "Y#it"; end > # end > # > # class Z < Y > # def it > # p "Z#it" > # superjump > # end > # end > # > # Z.new.it # outputs "X#it", "Z#it" > # > # Be careful. This method can't automatically pass the arguments of the > # caller like super does. You'll have to manually supply them. > def superjump(gap, *args) > method_name = caller[0][/in `(.*?)'/, 1].intern > klass = self.class.ancestors[1 + gap] > klass.instance_method(method_name).bind(self).call(*args) > end > > Regards, > Florian Gross