From: Jeremiah Bullfrog Date: 2004-09-14T17:34:54+09:00 Subject: Re: Recursive Objects (Arrays) in Ruby On Mon, 13 Sep 2004 20:54:21 -0700, Wandering Mango wrote: > #Problem line: > puts testFormula1.characterType[0] .... > test = Formula.new > test.string = "A&B" > test.wff > > Now, Ruby exits with the following complaint: > > in `wff': undefined method `characterType' for # > (NameError) I think the problem is, Ruby is not like C++ where one object can always read / change the internals of another if they're of the same class. It looks like Ruby's 'protected' might produce that C++ behavior but I haven't used it. Pickaxe pg 236 makes it look like it only works with methods and constants, ie you can't expose the raw variable itself. The easiest way to make accessors is to make the variable an 'attr'; eg class Formula attr :characterType # add ', true' if you want it writable too def initialize @string = nil @leftSub = nil @rightSub = nil @characterType = Array.new end # and I'm guessing something like this to give it C++ behavior # (ie what you were trying to do): protected characterType, characterType= # 'char..Type=' , only if you've specified a writer function # for char..Type .... end