Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2011 05:19
Show Gist options
  • Save anonymous/792872 to your computer and use it in GitHub Desktop.
Save anonymous/792872 to your computer and use it in GitHub Desktop.
class Person
def add_accessor(accessor_name)
self.class_eval %Q{
attr_accessor :#{accessor_name}
}
end
end
person = Person.new
Person.add_accessor :name
Person.add_accessor :gender
person.name = "Peter Cooper"
person.gender = "male"
puts "#{person.name} is #{person.gender}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment