I have an accounts model, where I would like the balance
to be readonly, but it can be updated via private methods.
Currently
class Account < ActiveRecord::Base
def deposit(amount)
# do some stuff and then
update_balance(amount)
end
private
def update_balance(amount)
self.balance += amount
end
end
However, this is still possible:
account = Account.first
account.balance += 5
account.save
I would like for the above to give an error, but still be able to do:
account.balance #=> 0
account.deposit(5)
account.balance #=> 5