Q:

In Rails, are class attributes of arbitrary classes reset on each new request?

Say I have a class Foo in my Rails App.
class Foo   
  @@bar = "hello"
  def self.change
    @@bar = "goodbye" 
  end

  def self.get_bar
    @@bar
  end 
end

If at some point, some user executes a controller action which includes
Foo.change

will Foo.get_bar return "goodbye" in every user session until the server is restarted?

A:

In the development environment, classes are reloaded on each request, so you will see class variables reset on each request.
In the production environment, classes are not reloaded on each request, so generally the class variables should be preserved across requests within a given Ruby process.
Bear in mind that some Rails servers might actually have multiple processes, so you're not guaranteed that all users and all requests will be sharing class variables.
Other Rails servers might be multi-threaded, so you have to be especially careful about how you mutate shared state (such as class variables).
For these reasons, it might be a good idea to avoid using class variables in this way as @andrew21 mentioned.

