Find a Ruby gem’s source directory
April 18, 2019
I often find myself opening a Ruby gem’s source directory in my code editor. I do this to read a gem’s README, to insert breakpoints for debugging or to understand the gem’s implementation. However, locating a gem’s source directory can be tricky / time consuming (especially so if you many Ruby versions installed on your machine).
Fortunately, there are handy utilites/commands that help swiftly locate a gem’s source.
If you’ve installed a gem using bundler, just run the bundle open
command to open the gem’s source in your preferred code editor
EDITOR=code bundle open devise
You can also ask bundler to just print the gem’s path
bundle show devise
However, If you’ve installed a gem using gem install
, you can use qwandry to locate the gem’s source.
First, install qwandry
gem install qwandry
and then run
qw --EDITOR code devise
Like bundler, qwandry too can print a gem’s path
qw --show devise