Newbie question: how come my class variable (“static” in Java/C#)
doesn’t retain its value in Rails? The following code works well in the
Ruby console (the number is incremented all the time even though new
instances are created), but in Rails it always restarts at 1.
In the /libs/ folder:
@@call_count = 0
def increment @@call_count += 1 "@@call_count incremented to " + @@call_count.to_s end
In the controller:
def index @s = StaticTest.new end
On the view:
Could it be that in Rails every single time the garbage collector cleans
up the class? I understand that controllers are instantiated on every
request, but I would expect my class variable @@call_count to retain its
value over requests, no?
Minh T. Nguyen.