# Using a @@class\_variable into a Module

**URL:** <https://www.ruby-forum.com/t/using-a-class-variable-into-a-module/138006>\
**Category:** Ruby\
**Created:** [May 19, 2008, 1:11pm UTC](https://www.ruby-forum.com/t/using-a-class-variable-into-a-module/138006 "2008-05-19T13:11:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [May 19, 2008, 1:11pm UTC](https://www.ruby-forum.com/t/using-a-class-variable-into-a-module/138006/1 "2008-05-19T13:11:26Z")

</div>

I resend this mail because it was considered SPAM, I hope it doesn’t  
appear twice.

I want to declare a @@class\_variable in class A.  
Class A includes a Module M and I want some methods in M using the  
@@class\_variable but I get some problem:

* * *

module M  
def kk  
#puts (eval %{ #{send(‘class’).class\_variables[0]} })  
puts @@class\_var  
end  
end

class A  
include M  
@@class\_var = “kaka1”  
end

## a = A.new a.kk NameError: uninitialized class variable @@class\_var in M from ./class\_attr1.rb:4:in `kk’

I understand the problem. Because the nature of class variables when  
the Module M uses @@ it looks into a class variable defined in same  
class/module.

Is there any way I could use a class A @class\_var into a included M  
module methods? If not then I’ll use a normal attribute but I don’t  
like it since it’s a constant value that could perfectly be a class  
variable instead of initialiting it in each A instance creation.

Thanks a lot.
