Skip to content

Instantly share code, notes, and snippets.

Created July 28, 2010 09:35
Show Gist options
  • Save anonymous/493867 to your computer and use it in GitHub Desktop.
Save anonymous/493867 to your computer and use it in GitHub Desktop.
class Admin < Person
include Log
watch_for_log :bar
end
Person.log_attributes --> ["foo"]
Admin.log_attributes --> ["foo", "bar"]
Person.log_attributes --> ["foo"]
module Log
def self.included(base)
base.extend(Log::ClassMethods)
end
module ClassMethods
base.attr_reader :log_attributes
def watch_for_log(*args)
@log_attributes ||= []
@log_attributes += args.collect(&:to_s)
@log_attributes += superclass.log_attributes if superclass.respond_to?(:log_attributes)
@log_attributes.uniq!
end
end
end
class Person
include Log
watch_for_log :foo
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment