New Project! ChatWithDesign 🛠️ AI Chat that can create, modify Figma files and even create websites.Try it now

Ruby Debugging Tip: Vendor-in Your Gems

March 21, 20152 min read

1  moIlCqF7EwjUmqiXagq3  Q

Coming to Ruby from Node.js, I was used to always having all my code at the tips of my fingers, right inside my sweet project. When I first came to Ruby, I was glad to have that distraction removed at first. Then about a year and a half or so later I was introduced by my co-worker Adam Maddox to vendoring gems in ruby.

bundle install --path=vendor/

This simple line installs all the gems into the vendor directory instead of the system gem directory. It creates a small file under .bundle/config to let bundler know to go through this new directory to find gems going forward.

Next just add it to the gitignore since we don't want this in our source control.

echo 'vendor/ruby' >> .gitignore

 Why Would You Ever Want This?

For starters it makes it much easier to debug your code by allowing you to put debug code right into the source code of your gems. Imagine you got a weird validation error and your application code is no where to be found in the stack trace. What do you do? Well if you have things vendored in, you can simply add binding.pry right on that specific line.

Another advantage is that you won't have to worry about different gems conflicting between ruby versions. Of course it is not a problem since we all know you are already using rbenv ;).

The real gem here is that you will be able to now find where all the magical methods you have been using reside. A simple search in your trusty code editor will reveal the truth!

Caveat

What happens if you don't want your searches to yield a ton of results coming from the vendor directory? Well Simply ignore that directory. If you are using sublime it is as simple as adding this to the where clause of your search.

-vendor/

That is it, happy coding :).

Also checkout heroku's blog for cool debugging tips.

© 2024 Michael Yagudaev