Rails: set a model attribute as read-only, but allow updating via method
<p>I have an accounts model, where I would like the <code>balance</code> to be readonly, but it can be updated via private methods.</p>

<p>Currently</p>

<pre><code>class Account &lt; ActiveRecord::Base
  def deposit(amount)
    # do some stuff and then
    update_balance(amount)
  end

  private

  def update_balance(amount)
    self.balance += amount
  end

end
</code></pre>

<p>However, this is still possible:</p>

<pre><code>account = Account.first
account.balance += 5
account.save
</code></pre>

<p>I would like for the above to give an error, but still be able to do:</p>

<pre><code>account.balance #=&gt; 0
account.deposit(5)
account.balance #=&gt; 5
</code></pre>