What is the use of .rb version in Ruby gem

It usually has a version.rb file that defines the gem version, for example:

module Foo VERSION = "0.0.1" end 

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

What is the advantage of this agreement?

-

Also, when using a namespace, the generated verison file can be deep in subfolders. Wouldn't it be easier to place version.rb directly under lib / and specify the version there?

+7
ruby gem
source share
3 answers

It depends on which stone maker you used. For example, a separate file makes it easier to stomp and rebuild, because you, for example, click version numbers using rake tasks. this is much easier than messing with the source file and trying not to damage anything.

Some packers use a separate VERSION file.

+2
source share

This is done in such a way as to reduce the outflow (change in speed) in the .gemspec file. I believe that dependency changes are much more important than version errors (which are also more frequent). Therefore, changes to the version would add too much noise and hide important commits.

+4
source share

In short, if your stone does not need to know the current version, you do not need version.rb . The event of some of the famous stones, such as rack , does not use it.

Suppose you create a complex stone that contains the -v option to see the current version, or you need to print the current version to warn the developers that there are some outdated changes, and then the require file in the stump version is much more convenient and efficient. than gemspec analysis.

This is just a congress in the Ruby community. The main reason why version.rb is because many gems are built on a bundler gem .

+2
source share

All Articles