Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望能够在给定对象上取消定义单例方法。
class A end a = A.new def a.foo puts "bar" end # undef a.foo here a.foo # should crash
class << a undef foo end
或者:
a.singleton_class.send :undef_method, :foo
class A end a = A.new def a.foo puts "bar" end a.instance_eval { undef :foo } a.foo # => undefined method `foo' for #<A:0x8469c60> (NoMethodError)