如何在运行时在Ruby中检查Gem版本?

时间:2021-09-14 07:29:01

Is it possible to check the gem version of the currently loaded gem in a ruby/rails app?

是否可以在ruby/rails应用程序中检查当前加载的gem版本?

During debugging, I would like to be able to do something like:

在调试过程中,我希望能够做以下事情:

puts RubyGem.loaded_version(:active_support)

Anything like that exist?

诸如此类的存在吗?

2 个解决方案

#1


54  

puts Gem.loaded_specs["activesupport"].version

#2


24  

careful when comparing against Gem.loaded_specs['mini_magick'].version as it's not a String but a Gem::Version object !

与Gem.loaded_specs['mini_magick']比较时要小心。版本不是字符串而是Gem: version对象!

the version string is accessible using Gem.loaded_specs['mini_magick'].version.version which is ugly and might not work as expected e.g. '2.2' > '2.10' !

使用Gem.loaded_specs['mini_magick'].version可以访问版本字符串。版本很丑,而且可能不像预期的那样工作。“2.2”>“2.10”!

the correct way to compare against a gem version is :

与gem版本进行比较的正确方法是:

Gem.loaded_specs['mini_magick'].version < Gem::Version.create('2.0')

Gem.loaded_specs[' mini_magick ']。版本< Gem::Version.create(“2.0”)

#1


54  

puts Gem.loaded_specs["activesupport"].version

#2


24  

careful when comparing against Gem.loaded_specs['mini_magick'].version as it's not a String but a Gem::Version object !

与Gem.loaded_specs['mini_magick']比较时要小心。版本不是字符串而是Gem: version对象!

the version string is accessible using Gem.loaded_specs['mini_magick'].version.version which is ugly and might not work as expected e.g. '2.2' > '2.10' !

使用Gem.loaded_specs['mini_magick'].version可以访问版本字符串。版本很丑,而且可能不像预期的那样工作。“2.2”>“2.10”!

the correct way to compare against a gem version is :

与gem版本进行比较的正确方法是:

Gem.loaded_specs['mini_magick'].version < Gem::Version.create('2.0')

Gem.loaded_specs[' mini_magick ']。版本< Gem::Version.create(“2.0”)