Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save grassdog/907401 to your computer and use it in GitHub Desktop.
Save grassdog/907401 to your computer and use it in GitHub Desktop.
Dynamically add instance methods to a Ruby class
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