开发者

Which format should the version constant of my project have

Ive seen lots of stuff

Foo::VERSION::STRING
Foo::VERSION
Foo:开发者_StackOverflow:Version

any suggestions what the best/most-common default is ?


First of all, Foo::Version seems wrong to me. That implicates that version is a Class or a Module, but should be a constant, as first two of your examples.

Apart from that, there is no golden rule here. Here are a few examples:

Rails:

    Rails::VERSION::STRING

(Note: a module VERSION with all capitals.)

SimpleForm:

    SimpleForm::VERSION

Nokogiri:

    Nokogiri::VERSION

RSpec:

    RSpec::Version::STRING

(Note, a module Version, compare with Rails above.)

Cucumber:

    Cucumber::VERSION

SimpleForm:

    SimpleForm::VERSION

Most of the above have their version defined in the lib/[name]/version.rb file, except for Rails, which has a version.rb in the root of the project, and Cucumber, which has buried it in the lib/cucumber/platform.rb file.

Also note that all of the above use Strings as a version. (Rails even concatenates MAJOR, MINOR, TINY, and PRE constants into a single VERSION constant.) This allows for easy comparison of versions:

    "1.2.3" > "0.4.2"  # => true
    "1.2.3" > "1.2.2"  # => true
    "1.2.3" > "1.2"    # => true

However, such a comparison fails when you run into double digits for the patch level:

    "1.2.3" > "1.2.12" # => true

To me, defining Foo::VERSION is your best bet, define it in lib/foo/version.rb, and make it a String value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜