Skip to content

Instantly share code, notes, and snippets.

@coxandrew
Created October 2, 2010 15:26
Show Gist options
  • Save coxandrew/607725 to your computer and use it in GitHub Desktop.
Save coxandrew/607725 to your computer and use it in GitHub Desktop.
class Object
def self.gimme_attrs(attr)
define_method("#{attr}") do
instance_variable_get "@#{attr}"
end
define_method("#{attr}=") do |attribute|
instance_variable_set :"@#{attr}", attribute
end
end
end
class Person
gimme_attrs :name
def initialize(name)
@name = name
end
end
p = Person.new('Frank')
puts p.name
p.name = 'Sam'
puts p.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment