Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Class
- def attr_accessor_with_history(attr_name)
- attr_name = attr_name.to_s
- attr_reader attr_name
- attr_reader attr_name+"_history"
- class_eval %Q{ @#{attr_name}_history = [nil] }
- class_eval %Q{ def #{attr_name}=(new_value)
- @#{attr_name}_history << @#{attr_name} = new_value
- end }
- end
- end
- class SomeOtherClass
- attr_accessor_with_history :bar
- attr_accessor_with_history :foo
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement