我需要为类的某些实例覆盖类方法
class Foo
def eigen_class
class << self
self
end
end
def self.foo
"original foo"
end
def override_foo
class << self
def self.foo
"overridden foo"
end
end
end
end
foo = Foo.new
foo.override_foo
foo.class.foo # => "original foo"
foo.eigen_class.foo # => "overridden foo"
foo2 = Foo.new
foo2.eigen_class.foo # => "original foo"
有没有办法在不显式获取特征类的情况下调用覆盖方法?