From: James Edward Gray II Date: 2005-07-26T02:57:54+09:00 Subject: Re: An array updatable? On Jul 25, 2005, at 12:45 PM, 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? Making a writer for it would mean you could set cars with code like: a.cars = Hash.new The code you show is not changing cars, it's just calling methods on the Array cars holds. If you want to disallow this, you'll need to do some forwarding, for the methods you wish to allow. However, I say think and make sure this is strictly necessary before you bolt down the gates. Don't kill yourself securing what doesn't strictly need securing. If I type a.cars.clear I either know what I'm doing or deserve to see things explode. It's my opinion that neither of those are your problem. ;) James Edward Gray II