-
-
Save workmad3/493876 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| end |
This file contains hidden or 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 --> nil |
This file contains hidden or 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 | |
| attr_accessor :log_attributes | |
| def watch_for_log(*args) | |
| @log_attributes ||= [] | |
| @log_attributes += args.collect(&:to_s) | |
| puts self.log_attributes.inspect | |
| end | |
| def log_attributes | |
| (@log_attributes + (superclass.respond_to?(:log_attributes) ? superclass.log_attributes : [])).uniq | |
| end | |
| end | |
| end |
This file contains hidden or 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