# Class variables

**URL:** <https://rubytalk.org/t/class-variables/12818>\
**Category:** ruby-talk\
**Created:** [29 July 2004 22:11 UTC](https://rubytalk.org/t/class-variables/12818 "2004-07-29T22:11:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![StephenSykes](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@StephenSykes](https://rubytalk.org/u/StephenSykes)\
**Post date:** [29 July 2004 22:11 UTC](https://rubytalk.org/t/class-variables/12818/1 "2004-07-29T22:11:43Z")

</div>

I know the rules for class variables have changed in 1.9, but I am not  
understanding this behaviour (this works ok in 1.8.x):

> > module M  
> > &nbsp;&nbsp;def self.included(klass)  
> > &nbsp;&nbsp;&nbsp;&nbsp;klass.class\_eval("@@y = 22")  
> > &nbsp;&nbsp;&nbsp;&nbsp;class \<\<klass  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@@x = 33  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;end  
> > end

=\> nil

> >

?\> class B

> > &nbsp;&nbsp;include M  
> > &nbsp;&nbsp;def show  
> > &nbsp;&nbsp;&nbsp;&nbsp;p @@y  
> > &nbsp;&nbsp;&nbsp;&nbsp;p @@x  
> > &nbsp;&nbsp;end  
> > end

=\> nil

> >

?\> B.new.show  
22  
NameError: uninitialized class variable @@x in B  
from (irb):14:in `show'  
from (irb):18  
$ ruby -v  
ruby 1.9.0 (2004-07-29) [i686-linux]

Stephen

> **···**
>
> from :0
