Accessing info about rubygem from within ruby script
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 variabl开发者_如何学编程e for further processing? res = c.execute
does not work.
You have different ways to achieve this:
Gem.source_index.find_name('somegem').last.full_gem_path
You could also just grep your load path:
$:.grep /somegem/
精彩评论