Let's see:

class A; end
a = A.new

Defines two objects.  A is an object whose proper class is Class, and a is
an object whose proper class is A. You can access these objects with:

A.class
a.class

a.class is A for all instances of the A class. A.class is Class, and that's
the same for all classes.

However, every object in Ruby also has a singleton class.  In a sense, this
class is a subclass of the object's proper class, so any changes you make
to it are reflected in the object, but not other objects with the same 
proper
class.  So the hierarchy looks something like:

   Class
     |
A-Singleton -> A
               |
          a-singleton -> a

If vertical means inheritence, and horizontal means "instance of".

Of course, it's more complicated than that, because a-singleton is an
instance of Class, so it has Class as its proper class, and
a-singleton-singleton as its singleton class. And Likewise
a-singleton-singleton is an instance of Class and has a proper class
and a singleton class.

So, about your examples:

for @x = 1, that's a class instance variable of the A class. It's
accessible using  A.class_eval { @x } or a.class.class_eval { @x }
You can make attribute writers/readers by doing:

class << A
    attr_reader :x
end

for @x = 2, it's also a class instance variable, but it uses the
singleton class of A instead of A itself. Since the singleton class
is exclusively related to A, it's no better than a class instance
variable of A, but in reality it's a class instance variable of the
singleton class of A. To write an accessor, you do:

def A.x
    class << self
       @x
    end
end

@x = 3 is a normal instance variable

@x = 4 is an instance variable of the singleton class of a, so it's
technically a class instance variable. However, since the singleton
class of a is only related to a, it's no better than an instance
variable of a in a different namespace.

Of course, you can go on as far as you want and make instance variables
like so:

def a.xN(N)
    return @x if N < 1

    cls = self

    N.times do
       cls = class << cls; self; end
    end

    cls.class_eval { @x }
end

So a.xN(1) would read the @x variable in a's singleton class, while
a.xN(2) would read the @x variable in the singleton class of a's
singleton class (I haven't tested this. It assumes that singleton
classes go up infinitely as necessary).

Of course, this would be pretty crazy, and I wouldn't recommend it.

Anyway, this has gone on very long, so I should stop. If you have
any more questions, I'll do my best to answer them, especially if
they're about the code I wrote.

Hope this has helped some.

- Dan