Pritam Dey wrote in post #1104053:
> My question is how @attr becomes Object class's class variable?

Not at my workstation to verify, but I'd suggest that this error:
> D:/Rubyscript/My ruby learning days/Scripts/TEST.RB:78: warning: class
> variable access from toplevel
is telling you that using a cvar inside #class_eval doesn't do what you
expect it should.  It appears to be searching for the cvar outside
the scope of class_eval (i.e. on the toplevel object, Object)

If I was at my workstation I'd use this to test:

    class A
      def A.bar
        @@bar
      end
    end
    class B
      class << self
        def foo
          A.class_eval { @@bar = 1 }
        end
      end
      def B.bar
        @@bar
      end
    end
    p A.bar, B.bar
    B.foo
    p A.bar, B.bar

(Just made up that code, haven't verified it in the slightest.)
I'd assume that A.bar would always return nil, and B.bar would return
nil and then 1.

Perhaps you should use:

    A.class_eval do
      class_variable_set :@@attr, 100
      # etc.
    end

(Again, I just made up that code, no idea if it's correct.)

-- 
Posted via http://www.ruby-forum.com/.