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?
Asked
Active
Viewed 1.4k times
2 Answers
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