Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the version from a gemspec file?

Tags:

ruby

gemspecs

Is there a clean way to extract the version string from a .gemspec file? (The gem is not yet installed)

e.g. somethingcool.gemspec is

Gem::Specification.new do |s|
  s.name = "somethingcool"
  s.version = "1.2.3"
  ... etc ...
end

I want to extract "1.2.3".

I could grep it out but there must be a better way.

like image 202
Gavin Brock Avatar asked Jul 16 '10 07:07

Gavin Brock


People also ask

How do I check RubyGems version?

You can check your Ruby version by running ruby --version , and you can check your RubyGems version by running gem --version . If you need to upgrade Ruby, use your ruby version manager's instructions. If you need to upgrade RubyGems, run gem update --system .

What is a Gemspec file?

Developer file that specifies the attributes of a RubyGems . GEM package; saves information such as the author, a description, an example usage, and the usage license; saved in a simple plain text format.

How do I install a specific version of a gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.


1 Answers

require "rubygems"

spec = Gem::Specification::load("example.gemspec")
puts spec.version
like image 106
duncan Avatar answered Oct 11 '22 15:10

duncan