Created
July 28, 2010 09:35
-
-
Save anonymous/493867 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
class Admin < Person | |
include Log | |
watch_for_log :bar | |
end |
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
Person.log_attributes --> ["foo"] | |
Admin.log_attributes --> ["foo", "bar"] | |
Person.log_attributes --> ["foo"] |
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 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 |
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
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