From: Summercool Summercool Date: 2007-09-16T22:14:08+09:00 Subject: Re: code quiz #1 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? > > 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? -- Posted via http://www.ruby-forum.com/.