On Mar 6, 2011, at 7:55 PM, JP Billaud wrote:

> Actually it seems that for some reasons the @@test class variables =
ended=20
> up in the Object class:
>=20
> puts Object.class_variables
>> @@test
>=20
> Anyway I am still confused about this... Help would very appreciated.

The snarky answer is: "Don't use class variables".  They really are hard =
to understand and generally don't have the semantics you expect or need.

The non-snarky answer is that when you do:

egA.class_eval do
 @@test =3D 5
end

Ruby does *not* evaluate '@@test' relative to self, which would be egA, =
but instead evaluates it relative to the lexical scope that is in =
effect, which in your code is the top level scope.  Class variables =
evaluated at the top level scope are instantiated within Object.

Most people expect class variables to only be visible to the class they =
are instantiated in but they are actually visible to their 'home' class =
as well as all subclasses.  Since every class is a subclass of Object, =
in your example, @@test becomes visible in every class and in every =
instance.

Gary Wright=