Class Variables - Static

Hello,

When setting the class static variables, These are shared across all the
instances created.

Class A
@@bool_var = true

def get_bool_var
@@bool_var
end
end

All the instances will have this static variable,
When through a controller, a user requests, Based on some logic, I set
the value to false.

Is this class static variable be set to false in all the other requests
from other users on a web application ?

Thank You.

On Monday, 26 May 2014 03:16:26 UTC-4, Ruby-Forum.com User wrote:

@@bool_var

The class variable will lose its value between requests in development
mode
due to class reloading. You SHOULD NOT use class variables to do this in
production, as the value is only available in the process where it was
set,
making multi-process deployments behave in ways you don’t expect.

–Matt J.

Thank You Jones for your answer,

I was suspecting that my class variable will not be the same at the same
request. I understand that on a multi-process deployment things would be
different.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs