Skip to content

Instantly share code, notes, and snippets.

@sesharim
Created November 2, 2014 21:02
Show Gist options
  • Save sesharim/c7eede8ed86892cfc7d0 to your computer and use it in GitHub Desktop.
Save sesharim/c7eede8ed86892cfc7d0 to your computer and use it in GitHub Desktop.
Modules
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
@sesharim
Copy link
Author

module Z
extend self

def hello
puts "HI"
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment