Created
October 2, 2010 14:20
-
-
Save briandonahue/607675 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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