Created
July 31, 2012 15:41
-
-
Save zeroeth/3217924 to your computer and use it in GitHub Desktop.
class eval is the devil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Class | |
| def attr_accessor_with_history attribute_name | |
| attr_reader "#{attribute_name}" | |
| attr_reader "#{attribute_name}_history" | |
| define_method "#{attribute_name}=" do |new_value| | |
| history = instance_variable_get("@#{attribute_name}_history") || [nil] | |
| instance_variable_set "@#{attribute_name}_history", history | |
| history << new_value | |
| instance_variable_set "@#{attribute_name}", new_value | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment