From: ts Date: 2001-10-06T23:05:17+09:00 Subject: [ruby-talk:22159] Re: Variables, constants, and scopes in Ruby >>>>> "A" == Alan Stern writes: Well, there are too many questions :-) A> There must be separate name tables for local variables, instance A> variables, class variables, and constants. (As an example, each A> object must contain a table of its own instance variables. And I A> assume each class object must contain a table of its class variables A> -- is that so?) At what times are these tables created? Where are A> they stored? When do they get pushed/popped on the name-lookup stack? * local variable are resolved at compile time and stored in the def * instance variable (and class variable) are stored in the object (with some small exceptions) and are resolved via the inheritence mechanism * constant are stored in the object but don't follow the same resolution than instance variable. This give you the possibility to write module A class B end end B is in reality A::B. If the resolution was the same than for instance variable you must write (to have the same effect) module A class A::B end end A> print "A instance variables: #{A.instance_variables}\n" You ask for variables with a name beginning with *only* one @ A> print "A class variables: #{A.class_variables}\n" You ask for variables with a name beginning with *two* @ A> Apparently there is special treatment for class variables. So where do A> they get stored? With the instance variables. Guy Decoux