Skip to content

Instantly share code, notes, and snippets.

@EricLondon
Last active August 29, 2015 14:06
Show Gist options
  • Save EricLondon/72952b77499badad4e29 to your computer and use it in GitHub Desktop.
Save EricLondon/72952b77499badad4e29 to your computer and use it in GitHub Desktop.
Rails Model Concern: track which classes have included the Concern
require 'active_support/concern'
module ChildTrackable
extend ActiveSupport::Concern
# keep track of what classes have included this concern:
module Children
extend self
@included_in ||= []
def add(klass)
@included_in << klass
end
def included_in
@included_in
end
end
included do
# track which classes have included this model concern
Children.add self
end
end
# access at:
ChildTrackable::Children.included_in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment