I’m new in the Ruby World and I have a question.
Let’s say I have a class with a class attribute (I call this class
Parent), this class attribute is used in instance methods of Parent.
Parent class has many subsclasses. Each subsclass should have it’s own
value of the class attribute.
@@test = nil
class Child1 < Parent
class Child2 < Parent
c1 = Parent.create ‘1’
c1.print_test # => 1
c2 = Parent.create ‘2’
c2.print_test # => 2
c1.print_test # => 2
What I’ll like, is that Child1 and Child2 have their own values of
@@test, but @@test should be initialized and used in Parent.
Also, @@test cannot be an instance variable because it is heavy to
initialize and will be common to all instances of Child1 or Child2.