Skip to content

Instantly share code, notes, and snippets.

@chad
Created January 19, 2011 14:25
Show Gist options
  • Save chad/786226 to your computer and use it in GitHub Desktop.
Save chad/786226 to your computer and use it in GitHub Desktop.
class LoggerClass
def self.attr_logger(attribute_name)
class_eval "def #{attribute_name}; @#{attribute_name}; end"
class_eval "def #{attribute_name}=(val); @#{attribute_name} = val; end"
end
end
class Person < LoggerClass
attr_logger :age
attr_logger :name
end
p Person.instance_methods(false)
chad = Person.new
chad.age = 321
puts chad.age
puts chad.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment