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
class Class
def attr_accessor_with_history(attr_name)
attr_name = attr_name.to_s # make sure it's a string
attr_reader attr_name # create the attribute's getter
attr_reader attr_name + "_history" # create bar_history getter
# write our setter code below
class_eval %Q(
def #{attr_name}=(attr_name)
@#{attr_name} = attr_name
unless @#{attr_name + "_history"}
@#{attr_name + "_history"} = []
@#{attr_name + "_history"} << nil
end
@#{attr_name + "_history"} << attr_name
end
)
end
end