Hi -- On Sun, 16 Sep 2007, Summercool Summercool wrote: > On Sep 16, 5:13 am, dbl... / wobblini.net wrote: > >> It's definitely a potential issue. You can protect against it by >> returning a dup of the array: >> >> class C >> attr_writer :a >> def a >> @a.dup >> end >> end > > > can using just the reader but not the writer protect the data better? It can protect the whole thing from being reassigned, but it can't protect mutable objects. In other words, even without a writer method you can still do: obj.name << "append this to a string" and if obj.name returns you the name string, then the name string will get changed. >>> 3) what is the "a = 123" near the line "class Foo" near the top of the >>> program? What is it, it is not local, not class variable, not instance >>> variable, not global... so what is it? the program is not complaining >>> the existence of it. >> >> It is local, actually. It's a local variable scoped to the outer level >> of the class definition body. It disappears inside method definitions, >> because "def" always starts a completely new local scope. > > > so is there much use of the local variable in the class level scope? > can you even have code / loop doing things... but when does it get > executed? It's executed as soon as Ruby sees it: class C x = 1 puts "Hello" puts x end If you run that, you get the output right away. It's not all that commonly used, I'd say. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)