Open a Ruby gem’s source

Quickly locate and open a Ruby gem’s source

April 18, 2019

#ruby

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.

Locate and open a gem installed by bundler

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

Locate and open a gem installed by rubygems

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

Source Code