Calling shadowed methods in an inherited object

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
···

Charles Comstock cc1@cec.wustl.edu 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