I need to get the installation path for a given ruby gem and can’t find any information on how to do that. Given:
#!/usr/bin/env ruby
require 'rubygems'
require 'somegem'
How can I find out where the installation path of somegem is on the system (without resorting to system(gem ...). The gem in question comes with some icons which I want to reference in my script.
Thanks to Chris I now have the following assembled:
require 'rubygems/Commands/contents_command'
c = Gem::Commands::ContentsCommand.new
c.options[:args] = 'somegem'
c.execute
However, c.execute immediately outputs the result on stdout. How can I catch that in a variable for further processing? res = c.execute does not work.
You have different ways to achieve this:
You could also just grep your load path: