12

I just started learning Ruby and I have been unable to find a good explanation on what is the difference between @@ and @ in terms of class variables. If anyone can provide a basic intuitive example, that would be really great. Also are they interchangeable?

bachkoi32
  • 1,426
  • 4
  • 20
  • 31
  • 2
    [This](http://www.railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/) site may be of help. – squiguy Jun 13 '13 at 22:10

2 Answers2

15

A variable prefixed with @@ is a class variable and one prefixed with @ is an instance variable. A great description can be found in this answer: https://stackoverflow.com/a/5890199/1181886

Community
  • 1
  • 1
Ryan Endacott
  • 8,772
  • 4
  • 27
  • 39
12

@ before a variable name : instance variable (one per instance)

@@ before a variable name : static variable (one per class)

Reda
  • 1,277
  • 1
  • 13
  • 27