问题描述
你如何确定哪个rubygem被用来响应require语句?宝石,这似乎没有帮助。
背景:对于项目hornsby-herbarium解析器,我正在使用宝石roo。
我使用github gem hmcgowan-roo,因为那时它比rubyforge版本的roo更新。我试着在runcoderun上测试代码,但它失败了,因为它没有任何版本的roo。到目前为止,新版本的roo在github和rubyforge都可用。
我决定不妨看看rubyforge的最新版本是否适用于我的代码,如我认为rubyforge比github forks更官方,权威,更稳定。一旦我确定rubyforge版本与我的代码一起工作,我会很好地询问runcoderun是否可以将它安装到他们的系统上。
我sudo gem安装了roo,并且我的宝石现在包括hmcgowan-roo(1.3.5)和roo(1.3.6),并且运行hornsby-herbarium-parser的测试仍然通过。我知道,由于rubyforge版本是最近安装的,它应该是测试中使用的版本,但我希望能够验证它。
gem其中
没有帮助,因为它给了我
pre $ (检查gem hmcgowan-roo-1.3.5 for roo)
/ usr / lib / ruby / gems / 1.8 / gems / hmcgowan-roo-1.3.5 / lib / roo.rb
更新:我同时使用了
$ :. detect {| dir | dir =〜/ roo /}
和
把Roo :: VERSION :: STRING
同意用gem,说我还在用hmcgowan-roo-1.3.5。
首先,rubygems会加载最高版本的gem,而不是最近安装的版本号。所以你应该在这里获得roo 1.3.6。除此之外,我第二个gerrit的建议是寻找一个版本常量。例如,我只是加载了rmagick,并且有一个不变的Magick :: Version。另一个例子是Open4 :: VERSION。然而,并非所有的gem都有版本常量,所以作为后备,你可以做一些像hacky的事情:
>>要求'open4'
=> true
>> $ :. detect {| dir | dir =〜/ \ / open4 - ([^ \ /] *)\ //}
=> /Library/Ruby/Gems/1.8/gems/open4-0.9.6/bin
>> $ 1
=> 0.9.6
How can you determine which rubygem is being used in response to a "require" statement? gem which doesn't seem to help.
Background: for the project hornsby-herbarium-parser, I'm using the gem roo.
I used the github gem hmcgowan-roo , as at that time it was more recent than the rubyforge version of roo. I tried testing the code on runcoderun, and it failed because it doesn't have any version of roo. By this time, new versions of roo were available on both github and rubyforge.
I decided I may as well see if the latest version from rubyforge works for my code, as I assume rubyforge is more official, authoritative, and stable than github forks. Once I'm sure the rubyforge version works with my code, I'll ask runcoderun nicely if they can install it on their system.
I sudo gem installed roo, and my gems now include "hmcgowan-roo (1.3.5)" and "roo (1.3.6)", and running the tests for hornsby-herbarium-parser still pass. I know that as the rubyforge version was installed more recently, it ought to be the one being used in the tests, but I want to be able to verify this.
gem which roo
Didn't help, because it gave me
(checking gem hmcgowan-roo-1.3.5 for roo)
/usr/lib/ruby/gems/1.8/gems/hmcgowan-roo-1.3.5/lib/roo.rb
which I assume is the wrong answer.
Update: I used both
$:.detect {|dir| dir =~ /roo/}
and
puts Roo::VERSION::STRING
both agree with gem which, saying that I'm still using hmcgowan-roo-1.3.5.
First of all, rubygems will load the highest version number gem, not the most recently installed. So you should be getting roo 1.3.6 here.
Other than that, I second gerrit's suggestion to look for a version constant. For instance, I just loaded rmagick and there is a constant Magick::Version. Another example is Open4::VERSION.
However not all gems have a version constant, so as a fallback you could do something hacky like:
>> require 'open4'
=> true
>> $:.detect {|dir| dir =~ /\/open4-([^\/]*)\//}
=> "/Library/Ruby/Gems/1.8/gems/open4-0.9.6/bin"
>> $1
=> "0.9.6"
这篇关于确定你正在使用哪个rubygem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!