class A
def initialize
@a = 10
end
def meth1
p @a
end
end
class B < A
def meth1
@a += 1
super
end
end
class C < B
def meth1
@a += 2
self.class.superclass.superclass.instance_method(:meth1).bind(self).call
end
end
a = A.new
b = B.new
c = C.new
a.meth1 #=> 10
b.meth1 #=> 11
c.meth1 #=> 12 作者: DeathKing 时间: 2010-11-14 08:47 回复 禾西 的帖子