Skip to content

Instantly share code, notes, and snippets.

@ngpestelos
Created October 1, 2013 20:49
Show Gist options
  • Save ngpestelos/6784881 to your computer and use it in GitHub Desktop.
Save ngpestelos/6784881 to your computer and use it in GitHub Desktop.
object extensions
# 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