Goodspeed IT Rants RSS

Rants from Goodspeed IT

Archive

Feb
15th
Sun
permalink

Ruby: gem which

I just stumbled across this today while doing some work on RCor:

gem which            Find the location of a library file you can require

Ok, so why is that useful?

Lets say you’re working on some ruby code with a line like:

require ‘concordion_test_case’

But ‘concordion_test_case’ isn’t in the project (which runs), so you deduce it must come from a gem.

For example: Rails applications are notorious for bundling all gem dependencies into ‘environment.rb’.  This can obscure which gem is used to fulfill the dependency.

The question is: which one?  The command “gem which” can solve this problem:

$ gem which concordion_test_case

(checking gem rcor-0.9.3 for concordion_test_case)

/usr/lib/ruby/gems/1.8/gems/rcor-0.9.3/lib/concordion_test_case.rb

The output will vary on different installations of ruby/gem, but the important bit to note is it told us which gem (& version) defines the symbol: “rcor-0.9.3”.