是否可以从单个实例中删除方法?
class Foo
def a_method
"a method was invoked"
end
end
f1 = Foo.new
puts f1.a_method # => a method was invoked
Run Code Online (Sandbox Code Playgroud)
我可以从已创建的对象中删除类a中的a_method:
class Foo
remove_method(:a_method)
end
Run Code Online (Sandbox Code Playgroud)
如果我从同一个对象调用a_method:
puts f1.a_method # => undefined method
Run Code Online (Sandbox Code Playgroud)
如果我创建另一个对象:
f2 = Foo.new
puts f2.a_method # => undefined method
Run Code Online (Sandbox Code Playgroud)
我怎样才能从特定的单个对象中删除方法?