T
Trans
Is there a way to do the "opposite" of binding a superclass method to
the current context? In other words, I want to call a method as if the
current binding were an instance of the superclass. For example, using
the method #public_methods as a basis of demonstration (could be any
method though):
class X
def a; "a"; end
end
class Y < X
def b; "b"; end
def public_methods(all=true)
# ?
self.class.superclass.instance_methodpublic_methods).bind(self).call(all)
end
end
y = Y.new
p y.public_methods(false)
Of course, that produces
['b', 'public_methods']
But what I want is:
['a']
I suspect there's no way to do this short of resorting to delegation
rather than subclassing. But I wanted to ask and make sure.
Thanks,
T.
the current context? In other words, I want to call a method as if the
current binding were an instance of the superclass. For example, using
the method #public_methods as a basis of demonstration (could be any
method though):
class X
def a; "a"; end
end
class Y < X
def b; "b"; end
def public_methods(all=true)
# ?
self.class.superclass.instance_methodpublic_methods).bind(self).call(all)
end
end
y = Y.new
p y.public_methods(false)
Of course, that produces
['b', 'public_methods']
But what I want is:
['a']
I suspect there's no way to do this short of resorting to delegation
rather than subclassing. But I wanted to ask and make sure.
Thanks,
T.