Hi Matz -- 

Any chance you could explain the rationale for this in a bit more detail? I
thought that class variable look up followed the inheritance hierarchy, not
the nesting hierarchy. For example:

class A
	@@x = :a
end

class B
	@@x = :b	
	class C < A
		def meth
			@@x
		end
	end	
end

p B::C.new.meth   # => :a   (ruby 1.8.0)


Why does class var look up in singleton methods follow the nesting hierarchy
instead?

TIA

-- George

> -----Original Message-----
> From: matz / ruby-lang.org [mailto:matz / ruby-lang.org]
> Sent: 10 November 2003 09:20
> To: ruby-core / ruby-lang.org
> Subject: Re: Class variable and singleton problem
> 
> 
> Hi,
> 
> In message "Class variable and singleton problem"
>     on 03/11/10, "mark.wassell" <mark.wassell / telstra.com> writes:
> 
> |I am wondering if the following is a bug or a feature (with 
> ruby 1.8.0). The following fails:
> |
> |	class A
> |		@@x=:a
> |	end
> |
> |	def (o=A.new).meth
> |		@@x
> |	end
> |
> |p o.meth # uninitialized class variable @@x in Object (NameError)
> 
> Class variables belongs to surrounding class (or module), so that @@x
> in meth does not belong to class A, but class Object.
> 
> 							matz.
>