How do you check the Gem Version in Ruby at Runtime?

梦想与她 提交于 2019-12-18 10:12:53

问题


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

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

puts RubyGem.loaded_version(:active_support)

Anything like that exist?


回答1:


puts Gem.loaded_specs["activesupport"].version



回答2:


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

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' !

the correct way to compare against a gem version is :

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



来源:https://stackoverflow.com/questions/2954279/how-do-you-check-the-gem-version-in-ruby-at-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!