Created
October 1, 2013 20:49
-
-
Save ngpestelos/6784881 to your computer and use it in GitHub Desktop.
object extensions
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
# see Metaprogramming Ruby, p. 118 | |
module MyModule | |
def my_method; 'hello'; end | |
end | |
obj = Object.new | |
class << obj | |
include MyModule | |
end | |
puts obj.my_method # "hello" | |
puts obj.singleton_methods # [:my_method] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment