If you’ve ever used Ruby you have probably used
Bundler through it’s command
bundle. There’s quite a few things you can do with
the more common
bundle install or
bundle exec, to the less frequently
In between those there is a very useful command,
bundle open, which will open
the code for a specified gem with an editor you can also configure.
Configuring the editor is as simple as defining an environment variable with
your editor of choice, which in my case is
Now, if I run
bundle open rails, I’ll have
vim open with the rails source
code for the version in the current bundle. Neat.
If you want to have something similar integrated with your editor you can look
ctags and how to install them in your
machine and editor. But it will basically go through source code of languages it
recognizes (a lot) and generate an index file for them, so that you can easily
look up methods, class definitions, etc.
For example, in my
vim setup I have a map of
fd (find definition) that uses
ctags, so that I can go directly from my source code to a gem’s source code and
back without ever leaving my editor.
The main issue with
ctags is that it’s pretty much a cache, and you need to
update it every time you install a gem or update its version. Luckily (and for
those of you who use
vim certainly not for the first time) Tim Pope comes to
the rescue with the
that will do that updating for you.
If you’ve enjoyed this Ruby Bit you should really subscribe to our newsletter, where other Ruby Bits and more great articles are shared every week.