0

The situation

The general idea is this: in the create method (in the controller) depending on a parameter, I have to run one of three methods as following:

case a
when 1..5
  runMethod1(a)
when 6
  runMethod2
when String
  runMethod3(a)
else
  puts "I have no idea what to do with that."
end

These methods are also defined in the same controller. Now, each method calls a particular library by using require. Those libraries aren't gems, they are files coded by me and located in the framework /lib path.

def runMethod1(a)
    require 'my_first_library'
    ...
end

What I am trying to do here is calling the library only when I need it, because each method might have an important processing and/or memory load on the system and I don't want to call all the libraries at the beginnig because I don't know if they all are gonna be used.

The Question

I'd like to know if Rails takes care of unloading this libraries when the method has finished or if it keeps it after the first call.

gingerEd
  • 83
  • 2
  • 4
  • P/S: I found [this][1] and [this][2] questions but they talk about Ruby and though it might be useful to this case, I don't know if Rails already handles it. [1]: http://stackoverflow.com/questions/19753060/is-it-possible-to-unload-un-require-a-ruby-library [2]: http://stackoverflow.com/questions/3424663/unload-a-ruby-class – gingerEd Sep 08 '15 at 15:59
  • Have you heard that Rails preloads every library in the app in production environment? Why do you care of loading/unloading certain classes/modules? – Anatoly Sep 08 '15 at 17:40
  • Thank you for answering. I didn't know that, I'm currently working in development mode. I just asked because I don't like the idea of having unrequired libraries consuming memory. You know if there's a way of avoiding this preload? – gingerEd Sep 14 '15 at 12:57

0 Answers0