问题
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