Undef singleton method from ruby ​​object

I would like to be able to undef the oneton method for this object.

class A end a = A.new def a.foo puts "bar" end # undef a.foo here a.foo # should crash 
+4
source share
2 answers
 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) 
+3
source
 class << a undef foo end 

As an alternative:

 a.singleton_class.send :undef_method, :foo 
+10
source

Source: https://habr.com/ru/post/1481949/


All Articles