thesecretmaster thesecretmaster - 4 months ago 17
Ruby Question

Install only part of a gem

I currently have a large gem installed that I only use part of. So, a few questions:


  • Is is possible to only install the part I need?

  • If so, does that make more sense then installing the whole thing and only
    require
    ing the part I need?


Answer

It is only possible to install the gem in its entirety, i.e. everything declared in the gemspec.

If so, does that make more sense then installing the whole thing and only requireing the part I need?

Only requiring what you need is exactly what you're looking for. If the gem is declared in your Gemfile like this:

gem "your_gem", require: false

Then, it won't be automatically required in your app and therefore, won't be loaded into memory, which seems to be the effect you want. Then, just require only the parts you need.