lulalala lulalala - 2 months ago 20
Ruby Question

What's the benefit of version.rb in Ruby gem

It is common to have a version.rb file, defining the version of the gem, like:

module Foo
VERSION = "0.0.1"
end


and in the .gemspec file, require the version.rb and use Foo::VERSION there.

What is the benefit of this convention?

--

Also, sometime when namespace is used, the generated verison file can be deeply in nested folders. Wouldn't it be easier to place a version.rb directly under lib/ and specifying the version there?

Answer

It depends on what gem builder you used. Having a separate file makes it easy to stomp and rebuild as you bump version numbers with rake tasks, for example. this is a lot easier than fiddling with a source file and trying not to damage anything.

Some packagers use a separate VERSION file.