Question

Working with Rails 3.2.1 and Ruby 1.9.3, where is the proper place to initialize a Global constant object such that it is only initialized once when the rails server is started.

Right now I am declaring it as instance object as and it is initialized every time the method is called:

@object_wanted_to_be_global_const = Gemname::GemnameClass.new 'input'

Where is the best place to declare this as a global constant variable?

If declared as a global instead of an instance, how will this affect performance as the variable is accessed on almost every request?

Was it helpful?

Solution

Put this in an initializer.

And to respect Ruby's convention, capitalize the whole name.

I can't see any performance issue regarding this method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top