在我的 Rails 模型中,我有类似的东西
def price Money.new(price_cents, currency) end
def price=(val)
price_cents = val.to_money.cents
end
def value
Money.new(value_cents, currency)
end
def value=(val)
value_cents = val.to_money.cents
end
def budget
Money.new(budget_cents, currency)
end
def budget=(val)
budget_cents = val.to_money.cents
end
def used
Money.new(used_cents, currency)
end
def used=(val)
used_cents = val.to_money.cents
end
这显然不是很干。我怎么能重构这个?