From: Daniel Doel Date: 2004-01-06T18:41:29+09:00 Subject: Re: Calling shadowed methods in an inherited object Charles Comstock wrote: > Gah that's nasty. You can get the superclass automatically with > > self.class.superclass > > so I guess you can do it with > > self.class.superclass.instance_method( :foo ).bind(self).call > > so I wonder if there is a way to make a singleton or temporary class > which could be returned by say parent allowing you to just use > > parent.foo > > to just do all of above. Clearly this doesn't seem to be something > that is supposed to be easy. Perhaps someone knows why? > > Thanks for the help anyway, > > Charlie Does this work? I don't have Ruby handy: class SuperProxy def initialize(obj) @obj = obj @class = obj.class.superclass end def method_missing(sym, *args, &blk) @class.instance_method(sym).bind(obj).call *args, &blk end end class Object def parent @proxy = SuperProxy.new(self) unless @proxy @proxy end end Apologies if there are formatting errors, I'm on webmail. - Dan