Gary Wright wrote in post #984168:
> On Feb 26, 2011, at 8:29 PM, Marc Chanliau wrote:
>
>>    @gender = gender
>>    puts
>> end
> Your example is quite unusual.  The scope of the 'person_instance'
> variable is only going to be within your class definition of Person.
> Basically you are creating several instances but then discarding any
> reference to them.  After the 'end' that terminates the Person
> definition 'person_instance' won't be defined and so the instance won't
> be accessible.
>
> It is important to realize that Ruby class definitions are actually
> executable code. The code within the class..end block is executed in the
> order it is written so that by the time you get to your "Person.new"
> calls, the class is defined as well as 'initialize' and 'printit' so
> there isn't anything magical going on when you call Person.new.
>
> Note, that if you moved your Person.new calls to between the definition
> of initialize and printIt, they would fail because they would be
> executed before printIt was defined.
>
> Gary Wright

Thanks, that's the type of explanation I was looking for. In summary, 
always instantiate outside the class (you probably can tell I'm coming 
from Java).

-- 
Posted via http://www.ruby-forum.com/.