Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

rubygems

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?

like image 566
Lance Avatar asked Jun 02 '10 00:06

Lance


People also ask

How do I check my gem version?

Since your goal is to verify a gem is installed with the correct version, use gem list . You can limit to the specific gem by using gem list data_mapper . To verify that it's installed and working, you'll have to try to require the gem and then use it in your code.

How do you check gems in ruby?

The Gem command is included with Ruby 1.9+ now, and is a standard addition to Ruby pre-1.9. Because local_gems relies on group_by , it returns a hash of the gems, where the key is the gem's name, and the value is an array of the gem specifications.

How do I specify a gem version?

There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .


1 Answers

puts Gem.loaded_specs["activesupport"].version 
like image 149
seangrieve Avatar answered Oct 07 '22 15:10

seangrieve