Created
November 2, 2014 21:02
-
-
Save sesharim/c7eede8ed86892cfc7d0 to your computer and use it in GitHub Desktop.
Modules
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) | |
puts base | |
base.instance_variable_set :@my_instance_variable, {} | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def my_instance_variable | |
# self is ClassA here, so we need to call superclass | |
superclass.instance_variable_get :@my_instance_variable # => {} | |
end | |
end | |
end | |
class MySuperClass | |
include MyModule | |
end | |
class ClassA < MySuperClass; end | |
puts ClassA.my_instance_variable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
module Z
extend self
def hello
puts "HI"
end
end