Skip to content

Instantly share code, notes, and snippets.

@banister
Forked from anonymous/gist:792872
Created January 24, 2011 05:20
Show Gist options
  • Save banister/792873 to your computer and use it in GitHub Desktop.
Save banister/792873 to your computer and use it in GitHub Desktop.
class Person
def add_accessor(accessor_name)
class << self; self; end.class_eval do
attr_accessor accessor_name
end
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