How to obtain gems compatibility version from Ruby

时间:2017-04-10 02:48:09

标签: ruby rubygems

Ruby gems are installed into directories called after the last compatible version rather than specific release. How can I obtain that version?

For example for Ruby 2.3.3, gems will be installed into 2.3.0 directory. How do I find out what that version is from a ruby interpreter?

3 个答案:

答案 0 :(得分:2)

其他答案是正确的,但使用路径。我追踪到了:

Gem.ruby_api_version

将自行返回该版本。

答案 1 :(得分:0)

Gem.loaded_specs

will give you a hash of loaded gems. From that list, choose one gem:

Gem.loaded_specs["did_you_mean"]
# => {"did_you_mean"=>#<Gem::Specification:0x2abac1f4ecb8 did_you_mean-1.0.0>}

gem_dir will give you the directory:

Gem.loaded_specs["did_you_mean"].gem_dir
# => ".../.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0"

In this case, I am using Ruby 2.3.3, and the gems are under the 2.3.0 directory.

答案 2 :(得分:0)

我在2.3.1中得到了同样的行为。这是提出&#34; 2.3.0&#34;:

的一种方式
% ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]

% ruby -e 'print Gem.user_dir'
/Users/kburnett/.gem/ruby/2.3.0

% ruby -e "print RbConfig::CONFIG['ruby_version']"
2.3.0