From: Eric Armstrong Date: 2006-07-14T09:40:38+09:00 Subject: Re: Initialize a variable in an extended class dblack@wobblini.net wrote: > On Fri, 14 Jul 2006, Eric Armstrong wrote: > >> Note: For a long time it wasn't clear to me that >> it is impossible to initialize an instance variable >> outside of a method. Coming from the Java world, I >> just assumed that this would be legal: >> class Foo >> @bar = 2 >> end >> >> But it isn't. (A fact that needs to be spelled out >> somewhere, for Java types.) > > I'm not sure what you mean by "somewhere". It gets talked about and > explained regularly here, as well as in various books, wikis, etc. > The workings of instance variables are not a closely guarded secret > :-) > Thanks for the smiley. I haven't been spending enough time here, it seems. :_) > When you see this: > > @var > > you are seeing an instance variable belonging to whatever object is, > at that point, playing the role of "self" (the default object). > > At the top level of a class definition block, "self" is the class > object (Foo in your example). > > So in your example, you've got an instance variable belonging to the > class object Foo. There's no connection at all between this instance > variable and any instance variable that may come into being later when > some other object is "self" (including an instance of Foo). > Getting clearer all the time. thanks. Now for the bigger problem... how to reuse data when I'm extending an existing class...