In this example …
class MyClass
@@myClassVar = [0,1,2,3,4,5,6,7,8, … 999]
blah, blah, blah
end
… is the class variable @@myClassVar constructed for each instance
of MyClass, or only once and referenced by all other instances? I
ask because I plan a class with some large class variables and/or
methods and am concerned about the effect on performance of
instanciating very many objects of the class.
Thanks
Chris
class MyClass
@@myClassVar = [0,1,2,3,4,5,6,7,8, ... 999]
blah, blah, blah
end
.... is the class variable @@myClassVar constructed for _each_
instance of MyClass, or only _once_ and referenced by all other
instances? I ask because I plan a class with some large class
variables and/or methods and am concerned about the effect on
performance of instanciating very many objects of the class.
Only once per interpreter. Using @@ is an effective way of caching.
-sc
···
--
Sean Chittenden
Thank you Sean and David.
Also thanks Matz and all contributors/collaborators; Ruby rocks!
Yours
Chris