How to change a scope of the accessor in model?

Hello all.
I have a table “Account” with the “value” column.
How i can change a scope for it, so that is will be only accessable in a
Account class? I’ve tried to overload a method, but no luck:

class Account < ActiveRecord::Base
private
def value=(amount)
write_attribute(:value, amount)
end
end
=> nil

ll = Account.new
=> #<Account:0xb6ef598c @new_record=true,
@attributes={“name”=>nil, “entity_id”=>nil, “updated_at”=>nil,
“currency_id”=>nil, “account_group_id”=>nil,
“value”=>#<BigDecimal:b6eafb6c,‘0.0’,4
(12)>, “base_value”=>#<BigDecimal:b6eafa18,‘0.0’,4
(12)>, “account_num”=>nil, “created_at”=>nil}>

ll.private_methods.include? “value=”
=> true

ll.value = 10
=> 10

ll.value
=> #BigDecimal:b718d064,‘0.1E2’,4(8)

  • Best regards, Nikolay P… <<<-----------------------------------
    ======================================================================

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs