>>>>> "A" == Alan Stern <stern / rowland.org> writes:

A> This is currently under discussion in a separate thread.  I think a

 I don't think so :-)

A> consensus is growing that class variables really ought to behave more
A> like instance variables of the class itself, with appropriate accessor
A> methods.

  Try this

   class A
      @var = 24
      class << self
         attr_accessor :var
      end
   end

   p A.var
   A.var = 12
   p A.var


 @var is an _instance variable_ for the class A, you don't need to change
 class variable because you have instance variables for class

A> That depends on how you look at it.  Since the code for a method is
A> only parsed once, if the parser resolved the local variables at
A> compile time then an occurrence of a variable like "i" would refer to
A> one fixed thing. 

 The parser resolve the local variables at compile time.

 A very simple example

pigeon% ruby -rii
dump
a = 12
c = b + a
^D
eval_tree         # this is the nodes created after the compile time
BLOCK
  NEWLINE <-:1>
  VCALL dump      # this is resolved as a method (first time that ruby see it)
  NEWLINE <-:2>
  LASGN a         # it has found an ``='' this mean that `a' is a local var
    LIT 12
  NEWLINE <-:3>
  LASGN c         # same here `c' is a local var
    CALL + 
      VCALL b     # `b' was never assigned (i.e. the local var `b' don't 
                  #  exist), ruby make a method call
      ARRAY
        LVAR a    # `a' was assigned, this is a local var

-:3: undefined local variable or method `b' for #<Object:0x401c6ce0> (NameError)
pigeon% 


A> While largely true, that's not entirely correct.  Ordinary objects and
A> classes differ in the way their metaclasses are created.  For
A> instance, suppose that x is an ordinary object (not a class) and that
A> C is a class.  Then C always has a metaclass -- it is created at the
A> same time as C (I think) -- but x only has a metaclass if you create
A> one explicitly.  Also, if C is a subclass of B, then Meta-C is a
A> subclass of Meta-B.  This means that, although Meta-x's superclass is
A> x's original class, Meta-C's superclass is not C's original class but
A> instead is C's superclass's metaclass.

 The meta-class can be seen as the class of the class

 Look at the ruby char hierarchy in object.c

A> Yes.  Do you know if there is any way, within the wrapper, to access
A> the original top-level object and class?

 the top-level in the wrapper is a clone of the original top-level, but
 it's easy to access class

pigeon% cat ff
A = ::Array
class A
   def A_NEW_METHOD_FOR_ARRAY
   end

   def clone
      raise "no clone for Array"
   end
end
pigeon% 

pigeon% ruby -e 'load "ff", true; p Array.instance_methods; [].clone'
["<=>", "first", "sort", "==", "nitems", "replace", "fill", "size",
 "indices", "delete", "&", "===", "inspect", "flatten", "index", "clone",  
 "reject!", "reverse_each", "collect", "reverse!", "unshift", "each",
 "to_a", "compact", "delete_at", "*", "uniq", "map!", "pop", "include?",
  "+",  "eql?", "empty?", "sort!", "last", "-", "slice", "assoc", "concat",
  "flatten!", "rindex", "clear", "length", "indexes", "join", "at", "[]", 
  "delete_if", "[]=", "each_index", "reverse", "to_s", "compact!", "<<", 
  "pack", "frozen?", "uniq!", "filter", "shift", "|", 
  "A_NEW_METHOD_FOR_ARRAY", "slice!", "rassoc", "to_ary", "hash", 
  "collect!", "push"]
./ff:7:in `clone': no clone for Array (RuntimeError)
        from -e:1
pigeon% 



Guy Decoux