From: Greg Millam Date: 2002-12-06T22:08:01+09:00 Subject: Re: Class-instance variables access > I try to understand the difference between 'class variables' and 'class > instance variables', following a post by Guy Decoux a few days ago. > If you've ever worked with C or Java, a class variable is like a variable declared 'static' class A def intialize(y) @x = y @@x = y end def test puts "@x: #{@x}" puts "@@x: #{@@x}" end end foo = A.new("foo") bar = A.new("bar") foo.test bar.test - You get: @x: foo @@x: bar @x: bar @@x: bar @x is an instance variable that each instance stores it's own version of @@x is a class variable that is stored in the class definition @x can be different from instance to instance, @@x is the same for all instances. -- Greg Millam walker at deafcode.com