Find file
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (28 sloc) 1.36 KB
= August 4, 2009
Fixed an issue with AssociationProxy so that it will properly provide a
respond_to? for dynamic methods for _in_cents. This fixes STI and other
association related problems not being able to access the converted amount.
= April 18, 2006
Moved the conversions code into its own module and used it to extend the Numeric
class, because I'll extend anything if given the chance. The following are not
only possible, but also fun:
3.00.to_cents #=> 300
300.to_dollars #=> 3.00
300.as_cents.to_cents #=> 300
3.00.as_cents.to_dollars #=> 3
3_000.to_cents #=> 300,000
= June 1, 2006
Hampton Catlin ( tossed me a patch which allows d&c to deal
with string values like a grownup. A few changes, and hey-presto you can now
do stuff like this:
@monkey.bribe = "300.20"
@money.bribe_in_cents == 30020 #=> true
"3.00".to_cents #=> 300
"300".to_dollars #=> 3.00
Also, as he points out, this means you can do this:
Please note that any non-numeric strings (e.g., "shazbot" or "twiddle") are
treated as 0, which means:
@monkey.bribe = 'banana' #=> 0.00, and @monkey.bribe_in_cents == 0
This is weird, personally, but it matches the way that ActiveRecord deals with
non-numeric strings being written to numeric attributes. Go fig.