Amin Shah Gilani
Amin Shah Gilani

Reputation: 9826

Active Model's method won't return a BigDecimal

Humans have a pay a percentage fee depending on how charitable they are.

class Human < ActiveRecord::Base
  def fee
    if charitable
      fee = BigDecimal('0.2')
    else
      fee = BigDecimal('0.5')
    end
    fee
  end
end

But why is it that when I run this on the console for Bob's fee, I get a Fixnum:

> bob.charitable
 => false # Ahh, so he should pay a fifty percent fee
> bob.fee
 => 0 # Whaaat? The dastardly bob has somehow H@X0R the system
> bob.fee.class
 => Fixnum # What? This was supposed to be a BigDecimal

Damn you Bob.

Help me beat Bob.

Upvotes: 0

Views: 29

Answers (1)

Amin Shah Gilani
Amin Shah Gilani

Reputation: 9826

Restart the console instead of reload! when you make changes to a Model.

Yes, I know, I'm stupid. But hey, someone else might be this stupid in the future. I'll just leave it here.

Upvotes: 1

Related Questions