Skip to content

Instantly share code, notes, and snippets.

@workmad3
Forked from anonymous/admin.rb
Created July 28, 2010 09:39
Show Gist options
  • Save workmad3/493876 to your computer and use it in GitHub Desktop.
Save workmad3/493876 to your computer and use it in GitHub Desktop.
class Admin < Person
end
Person.log_attributes --> ["foo"]
Admin.log_attributes --> nil
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
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