Skip to content

Instantly share code, notes, and snippets.

@nusco
Last active September 15, 2015 06:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save nusco/534678 to your computer and use it in GitHub Desktop.
Save nusco/534678 to your computer and use it in GitHub Desktop.
Spell: Class Extension
# ======================
# Spell: Class Extension
# ======================
# Define class methods by mixing a module into a class’s singleton class
# (a special case of Object Extension - http://gist.github.com/534667).
class C; end
module M
def my_method
'a class method'
end
end
class << C
include M
end
C.my_method # => "a class 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