I’m trying to retrieve the tax rate based on the timestamp. It doesn’t make sense to me to do a simple mixin where I define “tax_rate” in the Time class. It makes more sense to put “tax_rate” in a “Government” class (or module? I don’t know I’m new to this) and simply have the method be available to the Time class with an option to assume the current time if used on its own.
examples:
Time.now.tax_rate == 0.13
10.years_ago.tax_rate == 0.10
Government.tax_rate == 0.13 (assumes Time.now)
Where the method tax_rate is as follows:
def self.tax_rate
t = self || Time.now # I know this part won't work properly, I'll fix it later. I want it to default to using the current Time object or if the method is used on its own, the current time.
return 0.10 if t < Time.parse("July 1, 2001")
return 0.12 if t < Time.parse("July 1, 2010")
0.13
end
I basically need to reference tax rates in different classes in my rails project and I feel that putting it straight into one of the models just doesn’t fit right. It needs to be on its own.
Why not just have a
TaxRatemodule?If you want to define
tax_rateonTime, which I think is unnatural, then, just monkey patchTime.