Created
April 7, 2011 09:18
-
-
Save grassdog/907401 to your computer and use it in GitHub Desktop.
Dynamically add instance methods to a Ruby class
This file contains 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 ClassThatCanDynamicallyAddInstanceMethodsToItself | |
def define_method(method_name, &block) | |
method_carrying_module = Module.new do | |
define_method(method_name, &block) | |
end | |
self.extend method_carrying_module | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment