Advertisement
bkerby

Untitled

Jul 22nd, 2012
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class Class
  2. def attr_accessor_with_history(attr_name)
  3. attr_name = attr_name.to_s
  4. attr_reader attr_name
  5. attr_reader attr_name+"_history"
  6. class_eval %Q{ @#{attr_name}_history = [nil] }
  7. class_eval %Q{ def #{attr_name}=(new_value)
  8. @#{attr_name}_history << @#{attr_name} = new_value
  9. end }
  10. end
  11. end
  12.  
  13. class SomeOtherClass
  14. attr_accessor_with_history :bar
  15. attr_accessor_with_history :foo
  16. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement