From: Joel VanderWerf Date: 2005-07-26T02:53:31+09:00 Subject: Re: An array updatable? EdUarDo wrote: > Hi again, > > I have this class: > > class A > attr_reader :name, :cars > attr_writer :name > > def initialize(name) > @name = name > @cars = Array.new() > end > end > > a = A.new("xxxx") > a.cars << "vectra" << "megane" > puts a > > output: > > vectra > megane > > Why can I access cars and modify it if I have not declared it how > attr_writer. Must I simply declare it private? a.cars = nil # This gives an error The restriction is on the variable, not on the object that is bound to the variable. To restrict that object, you can #freeze it, but that will affect all access, including within the class A.