Skip to content

Instantly share code, notes, and snippets.

@mlangenberg
Created August 28, 2008 08:24
Show Gist options
  • Save mlangenberg/7679 to your computer and use it in GitHub Desktop.
Save mlangenberg/7679 to your computer and use it in GitHub Desktop.
module Lib
def self.my_attr_accessor(klass, attr)
klass.class_eval "def #{attr.to_s}; @#{attr.to_s}; end"
klass.class_eval "def #{attr.to_s}=(arg); @#{attr.to_s} = arg; end"
end
end
class Car
Lib::my_attr_accessor(self, 'color')
end
c = Car.new
c.color = 'rood'
puts c.color #=> 'rood'
c.color = 'groen'
puts c.color #=> 'groen'
puts "Hooray!!!!" #=> 'Hooray!!!!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment