Skip to content

Instantly share code, notes, and snippets.

@ljuti
Created December 3, 2009 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ljuti/247873 to your computer and use it in GitHub Desktop.
Save ljuti/247873 to your computer and use it in GitHub Desktop.
class AttrObject
def self.attr_logger(*args)
args.each { |attribute| define_method(attribute) {
value = instance_variable_get("@#{attribute}")
STDERR.puts "#{Time.now} - #{value}"
}}
end
end
class Person < AttrObject
attr_logger :first_name
attr_logger :last_name
def initialize
@first_name = "John"
@last_name = "Doe"
end
end
john = Person.new
john.first_name
john.last_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment