Created
April 23, 2012 12:20
-
-
Save ruprict/2470592 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyModule | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
def hellofrominstance | |
puts "hello from #{self}" | |
end | |
# Conventionally named ClassMethods | |
module ClassMethods | |
def hellofromclass | |
puts "Hello from #{self}" | |
end | |
end | |
end | |
# including MyModule will call the hook (#included) which | |
# extends the class methods | |
class Blah | |
include MyModule | |
end | |
pry(main)> Blah.hellofromclass | |
#=> "Hello from Blah" | |
pry(main)> Blah.new.hellofrominstance | |
#=> "hello from #" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment