I have the following code that I put in my controller which I am using
to initialize some static data. Note that it is not contained with a
method of any kind.
config = YAML.load_file(“config/config.yml”) if config.nil?
I would like this code to only be executed ONCE when the controller
class is loaded but what I am seeing is that every time I invoke a URL
that is related to this controller I see “test” printed on the console.
Which would indicate to me that this code is being executed on each
instantiation of the controller object, not just when the controller
class is loaded.
In irb, the code that’s just in a class but not in a method does only
get executed when the class is loaded not when new instances are made.
Is the controller class being reloaded each time???
P. S. I am trying to get the equivalent of a Java “static” block here.