
-----------------------------------
DtY
Mon Jul 13, 2009 3:32 pm

Getting Class Variables in class method
-----------------------------------
I wrote a class that keeps track of all the instances created in the variable @@settings, now I need a class method to read it back.

so, I have:
def UserSettings.all
@@settings
end
Which tells me that the class variable @@settings doesn't exist. It must be trying to read Class' @@settings, since this is inside a singleton method for Class. I tried @settings, which gave me nil (doesn't exist, I assume). So is there a method or something I can use to read a class variable?

-----------------------------------
Tony
Mon Jul 13, 2009 5:17 pm

Re: Getting Class Variables in class method
-----------------------------------
@var is the class variable

irb(main):001:0> class Foo
irb(main):002:1> @list = 

-----------------------------------
DtY
Mon Jul 13, 2009 7:14 pm

RE:Getting Class Variables in class method
-----------------------------------
Okay, thanks. If you can do it like that, what is the use of class variables? (Like with @@)

-----------------------------------
Tony
Tue Jul 14, 2009 9:11 am

RE:Getting Class Variables in class method
-----------------------------------
Wait, no... I've got things confused.

var -- local variable
@var -- instance variable
@@var -- class variable
$var -- global variable

The above _should_ be using @@class. I'm not entirely sure how it even works with the instance variable...

-----------------------------------
wtd
Tue Jul 14, 2009 12:31 pm

RE:Getting Class Variables in class method
-----------------------------------
Classes are objects.
