I have a question concerning best practices in rails. In my rails project I have the following code:
class MyController < ApplicationController
def some_method
@product = MyFabricatorClass.new.create_product
end
...
end
MyFabricatorClass is not dependent of some state and its behaviour is constant. I am also doing a lot of C++ stuff and to me it feels kind of unefficient to always instantiate a new MyFabricatorClass object. In a C++ project I would propably use something like:
class MyController < ApplicationController
@@my_fabricator = nil
def some_method
@@my_fabricator ||= MyFabricatorClass.new
@product = @@my_fabricator.create_product
end
...
end
Is this style also legit in Rails? What would be the typical rails way to do it?
Thanks for any advice...!