Search code examples
ruby-on-railsmetaprogrammingbundler

Rails Metaprogramming: where is this gem installed?


Quick metaprogramming question. In my rails 5 project, I'd like to find the installed location of a certain gem in code (ie. not command line).

I started with Bundler.install_path.

Looking under that, I see all the versions of the various gems I have installed for this ruby (I use rbenv, but this should work for rvm too).

/home/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/mygem-7eafb06c791d/ /home/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/mygem-3da2bf38d01a/

...and so on

Is there a way to tell Bundler "Can you tell me the directory where the gem mygem is installed? Or if there was a hash of gem names with their directories (or something like that), that's fine too.

bonus: if there's a guide to the inner workings of bundler, that'd be cool too :)


Solution

  • Bundler has the show command to show the location of a gem:

    bundle show mygem