Skip to content

Instantly share code, notes, and snippets.

@nusco
Last active September 5, 2015 18:54
Show Gist options
  • Save nusco/534667 to your computer and use it in GitHub Desktop.
Save nusco/534667 to your computer and use it in GitHub Desktop.
Spell: Object Extension
# =======================
# Spell: Object Extension
# =======================
# Define Singleton Methods by mixing a module into an object’s singleton class.
obj = Object.new
module M
def my_method
'a singleton method'
end
end
class << obj
include M
end
obj.my_method # => "a singleton method"
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment