Why .freeze and .dup SomeGem :: VERSION?
While I was reading https://github.com/thoughtbot/high_voltage source code, I found in the gem spec file:
Gem::Specification.new do |s|
s.name = 'high_voltage'
s.version = HighVoltage::VERSION.dup
and in the lib/high_voltage/version.rb
file:
module HighVoltage
VERSION = "2.2.1".freeze
end
What is the advantage of this?
+3
source to share
1 answer
According to http://alexpeattie.com/blog/defining-versions-in-ruby-gems/ it makes the string immutable, so it doesn't change accidentally.
0
source to share