Created
January 10, 2010 18:43
-
-
Save mxriverlynn/273675 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
# the verbose, annoying to maintain way :( | |
module MyModule | |
@@my_attribute = nil | |
def MyModule.my_attribute=(value) | |
@@my_attribute = value | |
end | |
def MyModule.my_attribute | |
@@my_attribute | |
end | |
end | |
#---- usage | |
MyModule::my_attribute = "some value" | |
puts MyModule::my_attribute #=> "some value" |
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
# the metaclass way :) | |
module MyModule | |
class << self | |
attr_accessor :my_attribute | |
end | |
end | |
#---- usage | |
MyModule::my_attribute = "some value" | |
puts MyModule::my_attribute #=> "some value" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment