Ruby 1.9.3 小版本 [英] Ruby 1.9.3 Teeny Version

查看:68
本文介绍了Ruby 1.9.3 小版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 RBConfig 来确定我的 ruby​​ 版本时,我在使用 ruby​​ 1.9.3 时得到了错误"的小版本:

When using RBConfig to determine my ruby version, I get the "wrong" teeny version when using ruby 1.9.3:

# ruby -v
ruby 1.9.3p286 (2012-10-12 revision 37165) [i686-linux]
# ruby -rrbconfig -e 'puts RbConfig::CONFIG.fetch(%q(MAJOR))'
1
# ruby -rrbconfig -e 'puts RbConfig::CONFIG.fetch(%q(MINOR))'
9
# ruby -rrbconfig -e 'puts RbConfig::CONFIG.fetch(%q(TEENY))'
1

使用 Ruby 1.8.7 - 这很好用:

Using Ruby 1.8.7 - this works fine:

$ ruby -v
ruby 1.8.7 (2012-06-29 patchlevel 370) [x86_64-linux]
$ ruby -rrbconfig -e 'puts Config::CONFIG.fetch(%q(MAJOR))'
1
$ ruby -rrbconfig -e 'puts Config::CONFIG.fetch(%q(MINOR))'
8
$ ruby -rrbconfig -e 'puts Config::CONFIG.fetch(%q(TEENY))'
7

我知道我可以获取补丁级别并稍微使用它,但是为什么 ruby​​ 1.9.3 返回 1 作为它的小版本?

I know I can get patchlevel and use that a bit, but why is ruby 1.9.3 returning 1 as its teeny version?

推荐答案

Ruby 有两个版本概念:实际发布版本和兼容版本".对于所有 Ruby 1.9.1 -> 1.9.3,兼容版本为 1.9.1,因为它们都向后兼容 1.9.1 版本.

Ruby has two concepts of version: The actual release version, and the "compatibility version". For all Rubies 1.9.1 -> 1.9.3, the compatibility version is 1.9.1, because they are all backward compatible with the 1.9.1 release.

RUBY_VERSION常量包含发布版本号,但如果这些值对您很重要,您将需要拆分这些点以获得 MAJOR、MINOR 和 TEENY:

The RUBY_VERSIONconstant contains the release version number, but you will need to split the dots to get the MAJOR, MINOR, and TEENY if those values are important to you:

>> major, minor, teeny = RUBY_VERSION.split(".")
=> ["1", "9", "3"]
>> teeny
=> "3"

也就是说,Ruby 版本号专门设计为可与 ASCII 进行比较,因此通常会看到这样的代码用于简单的版本检查:

That said, Ruby version numbers are specifically designed to be ASCII-comparable, so it is common to see code like this for simple version checks:

if RUBY_VERSION >= "1.9.3"
  #...
end

补丁级别通常可以忽略,因为补丁级别版本中没有 API 更改,只有错误修复和安全补丁.希望有帮助!

Patch level can typically be ignored, because there are no API changes in patch level releases, only bug fixes and security patches. Hope that helps!

这篇关于Ruby 1.9.3 小版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆