0
根據人們的慈善程度,人類需要支付一定比例的費用。活動模型的方法不會返回BigDecimal
class Human < ActiveRecord::Base
def fee
if charitable
fee = BigDecimal('0.2')
else
fee = BigDecimal('0.5')
end
fee
end
end
但爲什麼當我在控制檯Bob的費用上運行此,我得到一個Fixnum
:你鮑勃
> bob.charitable
=> false # Ahh, so he should pay a fifty percent fee
> bob.fee
=> 0 # Whaaat? The dastardly bob has somehow [email protected] the system
> bob.fee.class
=> Fixnum # What? This was supposed to be a BigDecimal
該死。
幫我打敗鮑勃。