
Untitled
By: a guest on Jan 28th, 2012 | syntax:
None | size: 0.44 KB | hits: 16 | expires: Never
attr_name = "price"
micron_read_method = "def #{attr_name}; read_attribute(:#{attr_name}) * 1000; end"
micron_write_method = "def #{attr_name}=(val); write_attribute(:#{attr_name}, val/1000); end"
evaluate_attribute_method attr_name, micron_read_method
evaluate_attribute_method attr_name, micron_write_method
> object.price = 10
> puts object.price
# 10
> object.price = 20
> puts object.price
# 20
> puts object.price_was
# 10000