Last active
August 29, 2015 14:05
-
-
Save kisai/237088e5607a1927a392 to your computer and use it in GitHub Desktop.
Meat: Add method to an instanced object
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
obj = SomeObject.new | |
obj.define_singleton_method(:new_method) do | |
"do some things" | |
end | |
# Using a mixin | |
module AdditionalMethods | |
def new_method | |
"do some things" | |
end | |
end | |
obj = SomeObject.new | |
obj.extend(AdditionalMethods) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment