简体   繁体   English

如何在Rails中检查gem版本

[英]How to check gem version within Rails

I was thinking about integrating a little feature into my CMS that checks for new releases of the gems that are installed. 我当时正在考虑将一个小功能集成到我的CMS中,以检查已安装的gem的新版本。 Is there a way to check the current installed version of a Gem from within the application/rails console? 有没有办法从应用程序/ rails控制台中检查Gem的当前安装版本?

In theory, you can access the rubygems api via the Gem class: 从理论上讲,您可以通过Gem类访问rubygems api:

Gem.latest_version_for "pry"

# => Gem::Version.new("0.9.12.6")

To get the list of current gems, you can try this. 要获取当前宝石的列表,可以尝试一下。

gems = Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
gems["pry"].version
# => Gem::Version.new("0.9.12.4")

Blatantly stolen from here. 这里被公然偷走

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM