# Accessing class instance variable from instance method

**URL:** <https://rubytalk.org/t/accessing-class-instance-variable-from-instance-method/11989>\
**Category:** ruby-talk\
**Created:** [8 June 2004 09:25 UTC](https://rubytalk.org/t/accessing-class-instance-variable-from-instance-method/11989 "2004-06-08T09:25:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehr\_Assaph\_Assaph](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Mehr\_Assaph\_Assaph](https://rubytalk.org/u/Mehr_Assaph_Assaph)\
**Post date:** [8 June 2004 09:25 UTC](https://rubytalk.org/t/accessing-class-instance-variable-from-instance-method/11989/1 "2004-06-08T09:25:03Z")

</div>

> Sorry. See subject. (To access class instance variable from inside  
> instance method).

> My very small rant is, accessing class variables (@@var) from inside  
> instance method is much easier and more straightforward; however, I

tend

> to use class instance variable more often, since in Ruby1.x @@var is  
> shared in subclasses (IIRC this will change in Ruby2). I've never find

a

> use for @@var so far in my programs.

But you're trying to access a (private) variable on a completely  
different, and only vaguely related, object. Why should you have a  
"nice" way?  
I don't often use @@var either. I use a class instance variable only  
when it has to do with the internal mechanics of the object representing  
the class, nothing for the objects instanciated from the class top muck  
around with.

---

<div class="post-metadata">

**Author:** ![David\_Garamond2](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@David\_Garamond2](https://rubytalk.org/u/David_Garamond2)\
**Post date:** [8 June 2004 09:55 UTC](https://rubytalk.org/t/accessing-class-instance-variable-from-instance-method/11989/2 "2004-06-08T09:55:08Z")

</div>

Mehr, Assaph (Assaph) wrote:

> > My very small rant is, accessing class variables (@@var) from inside instance method is much easier and more straightforward; however, I
> 
> tend
> 
> > to use class instance variable more often, since in Ruby1.x @@var is shared in subclasses (IIRC this will change in Ruby2). I've never find
> 
> a
> 
> > use for @@var so far in my programs.
> 
> But you're trying to access a (private) variable on a completely  
> different, and only vaguely related, object. Why should you have a  
> "nice" way?

Then perhaps Ruby should not provide a "nice" way to access @@var too 🙂

> **···**
>
> > I don't often use @@var either. I use a class instance variable only  
> > when it has to do with the internal mechanics of the object representing  
> > the class, nothing for the objects instanciated from the class top muck  
> > around with.
> 
> --  
> dave
