"Christoph Rippel" <crippel / primenet.com> writes:

> In general nice it might be nice if your book could point out in
> a  comprehensive fashion the somewhat confusing differences
> between a
> 
> -- variable local to an object

  instance variables

> -- class variable

  class variables

> -- variable local to the Class

  I assume you mean instance variables  within the class

> -- variable local to the Meta Class

  I have no idea what this is :)



From your examples, I'm not sure I see where the confusion is. The
only possible strangeness appears to be the expectation that

   class Fred
     @var = 123
   end

sets an instance variable for objects of class Fred, rather than for
Fred itself.

When I think about classes in Ruby, I have a very simple model.  There
really is only one basic structure: an instance with some state, and
chained off it a list of classes,? each of which contains a list of
methods. Then there's the twist: classes are object instances too, and
so have their own state and list of classes, and so on. Classes that
Ruby generates internally? are called singletons, and are mostly the
same as any other class, except they're invisible.

Then there's just one more thing: when defining a class, you're
executing code in the context of that class object:

  class Dave
    p self       #=>  Dave
  end

Instance variables are always defined in terms of the current value of 
self.

Once this picture was clear, I found that I can understand pretty
intuitively what the scope of various constructs should be.  I tried
to set all this down in chapter 19. However, this just represents my
own warped way of thinking: I'm sure others will have different ways
of visualizing the hypercube :)


Regards


Dave




Footnotes: 
?  or class proxies for included modules.

?  for example, the class of a Class, and classes generated for
specific objects (class <<a)