class Class def attr_accessor_with_h istory attr_name attr_name attr_n

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Class
def attr_accessor_with_history(attr_name)
attr_name = attr_name.to_s
attr_hist_name = attr_name+'_history'
#getter
self.class_eval("def #{attr_name};@#{attr_name};end")
#setter
self.class_eval %Q{
def #{attr_name}=(val)
# add to history
@#{attr_hist_name} = [nil] if @#{attr_hist_name}.nil?
@#{attr_hist_name} << val
# set the value itself
@#{attr_name}=val
end
def #{attr_hist_name};@#{attr_hist_name};end
}
end
end