How do you check the Gem Version in Ruby at Runtime?
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)
Anyt开发者_运维百科hing like that exist?
puts Gem.loaded_specs["activesupport"].version
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')
精彩评论