Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undef singleton method from ruby object

Tags:

ruby

I would like to be able to undef a singleton method on a given object.

class A
end

a = A.new
def a.foo
  puts "bar"
end

# undef a.foo here
a.foo # should crash
like image 794
Abdo Avatar asked Dec 07 '22 07:12

Abdo


1 Answers

class << a
  undef foo
end

Alternatively:

a.singleton_class.send :undef_method, :foo
like image 99
Marc-André Lafortune Avatar answered Dec 29 '22 00:12

Marc-André Lafortune