当我在阅读时 https://github.com/thoughtbot/high_voltage源代码,我在 gem 规范文件中找到:
Gem::Specification.new do |s|
s.name = 'high_voltage'
s.version = HighVoltage::VERSION.dup
在 lib/high_voltage/version.rb
文件中:
module HighVoltage
VERSION = "2.2.1".freeze
end
这样做有什么好处?
最佳答案
根据 http://alexpeattie.com/blog/defining-versions-in-ruby-gems/ , 它使字符串不可变,因此不会意外更改。
关于gem - 为什么使用 .freeze 和 .dup SomeGem::VERSION?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27561476/