# What does "@@" mean?

**URL:** <https://www.ruby-forum.com/t/what-does-mean/158042>\
**Category:** Ruby\
**Created:** [January 18, 2009, 1:34pm UTC](https://www.ruby-forum.com/t/what-does-mean/158042 "2009-01-18T13:34:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 18, 2009, 1:34pm UTC](https://www.ruby-forum.com/t/what-does-mean/158042/1 "2009-01-18T13:34:49Z")

</div>

In a ruby class, what does a variable “@@name” mean? Does it mean static  
variable? Does its subclass have access to this field?

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 18, 2009, 1:57pm UTC](https://www.ruby-forum.com/t/what-does-mean/158042/2 "2009-01-18T13:57:19Z")

</div>

Hi –

On Sun, 18 Jan 2009, Zhao Yi wrote:

> In a ruby class, what does a variable “@@name” mean? Does it mean static  
> variable? Does its subclass have access to this field?

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

–  
David A. Black / Ruby Power and Light, LLC  
Ruby/Rails consulting & training: [http://www.rubypal.com](http://www.rubypal.com)  
Coming in 2009: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://manning.com/black2))

[http://www.wishsight.com](http://www.wishsight.com) =\> Independent, social wishlist management!

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 18, 2009, 2:08pm UTC](https://www.ruby-forum.com/t/what-does-mean/158042/3 "2009-01-18T14:08:46Z")

</div>

David A. Black wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 18, 2009, 2:30pm UTC](https://www.ruby-forum.com/t/what-does-mean/158042/4 "2009-01-18T14:30:53Z")

</div>

On 18.01.2009 14:07, Zhao Yi wrote:

> David A. Black wrote:
> 
> > 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 🙂

> Ok thanks. That’s why I always got error when access to this variable  
> outside of the class-hierarchy.

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.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 18, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/what-does-mean/158042/5 "2009-01-18T20:09:40Z")

</div>

On Sun, Jan 18, 2009 at 11:28 AM, Robert K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.

‘Beast’ was a fun name for them. 🙂  
You can use like it like this:

> <https://gist.github.com/48743>

Regards!

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [January 18, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/what-does-mean/158042/6 "2009-01-18T20:10:51Z")

</div>

On Sun, 18 Jan 2009 07:33:29 -0500, Zhao Yi wrote:

> In a ruby class, what does a variable “@@name” mean? Does it mean static  
> variable? Does its subclass have access to this field?

“static variable” means different things in different contexts in C and  
Java, but @@variables are roughly equivalent to those defined by  
following Java code:

public class Foo{  
private static int bar=0;  
}
