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 #make sure it's a string
- attr_reader attr_name #create the attribute's getter
- attr_reader attr_name+"_history" #create the bar_history getter
- class_eval %Q{
- def #{attr_name}=(val)
- @#{attr_name} = val
- @#{attr_name}_history = (@#{attr_name}_history || []) << val
- end
- } #when you set the attribute, you set it and save it to an array
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement