Created
September 12, 2009 02:40
-
-
Save besquared/185702 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 | |
module ClassMethods | |
def my_method | |
@myvar ||= 0 | |
end | |
def my_method=(value) | |
@myvar = value | |
end | |
end | |
end | |
class MyClass | |
include MyModule | |
end | |
puts MyClass.my_method | |
MyClass.my_method = 5 | |
puts MyClass.my_method | |
class AnotherClass | |
include MyModule | |
end | |
puts MyClass.my_method | |
puts AnotherClass.my_method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment