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.3k times
2 Answers
14
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,084
- 4
- 26
- 39
12
@ before a variable name : instance variable (one per instance)
@@ before a variable name : static variable (one per class)
Reda
- 1,237
- 1
- 13
- 26