How can I get the version of a gem using just Ruby? I'd rather not use a system call and grep it the shells output like:
`gem search passenger`.scan(/(?:\(|, *)([^,)]*)/).flatten.first
=> "2.2.9"
Can't I just get it somehow with:
Gem::Version
I just don't know how to specify the gem I want, like in this case I want to get the Passenger gem's newest version.
The rubygems' API is well documented.
The example you've been looking for:
>>> require 'rubygems'
>>> si = Gem::SourceIndex.from_installed_gems
>>> gems = si.find_name('rails')
>>> gems.each { |gem| puts gem.version.version }
2.3.5
From "Determining which rubygem you're using":
Gemname::VERSION::STRING
also works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With