如何从 gemspec 文件中获取版本? [英] How do I get the version from a gemspec file?

查看:44
本文介绍了如何从 gemspec 文件中获取版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种干净的方法可以从 .gemspec 文件中提取版本字符串?(gem 还没有安装)

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

例如somethingcool.gemspec 是

e.g. somethingcool.gemspec is

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

我想提取1.2.3".

I want to extract "1.2.3".

我可以解决它,但一定有更好的方法.

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

推荐答案

require "rubygems"

spec = Gem::Specification::load("example.gemspec")
puts spec.version

这篇关于如何从 gemspec 文件中获取版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆