Z
Zhao Yi
In a ruby class, what does a variable "@@name" mean? Does it mean static
variable? Does its subclass have access to this field?
variable? Does its subclass have access to this field?
In a ruby class, what does a variable "@@name" mean? Does it mean static
variable? Does its subclass have access to this field?
David said:It's a class variable, which is actually a class-hierarchy variable
(shared between a class and its descendants), and also visible to all
the instances of all of those classes.
In other words, it's a kind of class-hierarchy-scoped global. Think of
it as $$name
David
Ok thanks. That's why I always got error when access to this variable
outside of the class-hierarchy.
In a ruby class, what does a variable "@@name" mean? Does it mean static
variable? Does its subclass have access to this field?
Actually I would recommend against using this beast. There are some subtle
issues with regard to definition order. Better use an instance variable of
the class instance.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.