Skip to content

Instantly share code, notes, and snippets.

@nusco
Created August 18, 2010 14:58
Show Gist options
  • Save nusco/535001 to your computer and use it in GitHub Desktop.
Save nusco/535001 to your computer and use it in GitHub Desktop.
Spell: Class Extension Mixin
# ============================
# Spell: Class Extension Mixin
# ============================
# Enable a module to extend its includer through a Hook Method (http://gist.github.com/534994).
module M
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def my_method
'a class method'
end
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