>>>>> "g" == george marrows <george.marrows / ps.ge.com> writes:


 If I've well understood

g> class B
g> 	@@x = :b	

 this class variable belong to the class B (this is the surrounding class)

g> 	class C < A
g> 		def meth
g> 			@@x

 ruby search the surrounding class, which is C then it look in the
 inheritence hierarchy to find it.

g> 		end

>> |
>> |	class A
>> |		@@x=:a

 This class variable belong to the class A

>> |	end
>> |
>> |	def (o=A.new).meth
>> |		@@x

 ruby search the surrounding class, which is Object and search in it
 This is like if you have written

   o = A.new
   class << o
      def meth
         @@x
      end
   end

 The first surrounding class is a _singleton_ class (the singleton class
 associated to `o'), then ruby search the next surrounding class and find
 Object : it then search in Object

 You have the same thing with

   class A
      @@x = :a
   end

   class << A
      def meth
         @@meth
      end
   end

 but it will work with

   class A
      @@x = :a

      class << A
         def meth
            @@meth
         end
      end
   end

 The first surrounding class is the _singleton_ class A, the next surrounding
 is A and ruby search in A


Guy Decoux