gist: 7680 Download_button fork
public
Public Clone URL: git://gist.github.com/7680.git
car.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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!!!!'

Owner

mlangenberg

Revisions