Skip to content

Instantly share code, notes, and snippets.

@wrpinheiro
Created August 21, 2014 02:07
Show Gist options
  • Save wrpinheiro/e2571ebfbfc1f8e08f24 to your computer and use it in GitHub Desktop.
Save wrpinheiro/e2571ebfbfc1f8e08f24 to your computer and use it in GitHub Desktop.
Ruby include & extend
# Version 1
# Some basic include & extend approach
module AnyModule
def an_instance_method
end
module ClassMethods
def a_class_method
end
end
end
class AnyClass
include AnyModule
extend AnyModule::ClassMethods
end
# Version 2
# Use method hook self.included
module AnyModule
def self.included(base)
base.extend(ClassMethods)
end
def an_instance_method
end
module ClassMethods
def a_class_method
end
end
end
class AnyClass
include AnyModule
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment