# By alan snape # All rights reserved. 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 class_eval %Q| @#{attr_name} = nil @#{attr_name}_history = nil def #{attr_name} @#{attr_name} end def #{attr_name}=(value) if @#{attr_name} then @#{attr_name}_history.push(@#{attr_name}) else @#{attr_name}_history = [@#{attr_name}] end @#{attr_name} = value end def #{attr_name}_history @#{attr_name}_history end | end end