Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从ruby脚本中访问关于rubygem的信息_Ruby_Rubygems - Fatal编程技术网

从ruby脚本中访问关于rubygem的信息

从ruby脚本中访问关于rubygem的信息,ruby,rubygems,Ruby,Rubygems,我需要获取给定ruby gem的安装路径,但找不到任何关于如何执行此操作的信息。鉴于: #!/usr/bin/env ruby require 'rubygems' require 'somegem' 如何找到somegem的安装路径在系统上的位置(无需求助于system(gem…)。有问题的gem带有一些我想在脚本中引用的图标 多亏了Chris,我现在组装了以下组件: require 'rubygems/Commands/contents_command' c = Gem::Commands

我需要获取给定ruby gem的安装路径,但找不到任何关于如何执行此操作的信息。鉴于:

#!/usr/bin/env ruby
require 'rubygems'
require 'somegem'
如何找到
somegem
的安装路径在系统上的位置(无需求助于
system(gem…
)。有问题的gem带有一些我想在脚本中引用的图标

多亏了Chris,我现在组装了以下组件:

require 'rubygems/Commands/contents_command'
c = Gem::Commands::ContentsCommand.new
c.options[:args] = 'somegem'
c.execute

但是,
c.execute
会立即在标准输出上输出结果。如何在变量中捕获该结果以便进一步处理?
res=c.execute
不起作用。

您有不同的方法来实现这一点:

Gem.source_index.find_name('somegem').last.full_gem_path
您还可以grep加载路径:

$:.grep /somegem/

谢谢,Gem.source\u索引方法正是我所需要的。