Skip to content

Instantly share code, notes, and snippets.

@briandonahue
Created October 2, 2010 14:20
Show Gist options
  • Save briandonahue/607675 to your computer and use it in GitHub Desktop.
Save briandonahue/607675 to your computer and use it in GitHub Desktop.
class SomeClass
def sumpm
puts "You found me!"
end
def singleton_class
class << self; self; end
end
def remove_method(method_name)
copy = self.dup
p copy.methods.sort
p copy.singleton_class.instance_methods.sort
copy.singleton_class.send(:undef_method,method_name)
copy
end
end
e = SomeClass.new
def e.blah
puts "In blah"
end
e.blah
# This fails with method not found
x = e.remove_method(:blah)
x.blah
e.blah
# This works
e.sumpm
x = e.remove_method(:sumpm)
x.sumpm
e.sumpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment