Last active
December 16, 2015 13:59
-
-
Save scudelletti/5445946 to your computer and use it in GitHub Desktop.
attr_accessor for Class Variables
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 XptoModule | |
class << self | |
attr_accessor :classes_with_xpto_module | |
end | |
self.classes_with_xpto_module = [] | |
def self.included(base) | |
self.classes_with_xpto_module << base | |
end | |
end | |
class XptoClassOne | |
include XptoModule | |
end | |
class XptoClassTwo | |
include XptoModule | |
end | |
XptoModule.classes_with_xpto_module # => [XptoClassOne, XptoClassTwo] | |
class XptoClassThree | |
include XptoModule | |
end | |
XptoModule.classes_with_xpto_module # => [XptoClassOne, XptoClassTwo, XptoClassThree] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment