Skip to content

Instantly share code, notes, and snippets.

@scudelletti
Last active December 16, 2015 13:59
Show Gist options
  • Save scudelletti/5445946 to your computer and use it in GitHub Desktop.
Save scudelletti/5445946 to your computer and use it in GitHub Desktop.
attr_accessor for Class Variables
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