I’ve been looking at the source code of a few gems lately. One idiom that I keep seeing is the use of a nested module containing version constants that are joined into a version string i.e. variations around this sort of thing:
module ChunkyBacon
module Version
MAJOR = 0
MINOR = 6
TINY = 2
end
VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].compact * '.'
end
What’s the advantage (if any) of storing the library version information in this way? Why not just do:
module ChunkyBacon
VERSION = '0.6.2'.freeze
end
For programmatic compatibility checks, it’s easier to have an explicitly separated version number.
e.g.: