Ruby 1.9.3 Teeny Version

你说的曾经没有我的故事 提交于 2019-12-02 01:16:52

问题


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

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

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


回答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.

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"

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

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!




回答2:


Looks like Minor is just reporting on the library minor - ok. So all I am left with is the ruby_version string - better than nothing.

# /usr/bin/ruby -rrbconfig -e 'print RbConfig::CONFIG.fetch(%q(LIBRUBY_SO))'
libruby.so.1.9.1
# /usr/bin/ruby -rrbconfig -e 'print RbConfig::CONFIG.fetch(%q(ruby_version))'
1.9.3-p286

ruby 1.8 shows this:

$ /usr/bin/ruby -rrbconfig -e 'print RbConfig::CONFIG.fetch(%q(LIBRUBY_SO))'
libruby1.8.so.1.8.7

and ruby 1.9.2-p320 this:

$ ruby -rrbconfig -e 'print RbConfig::CONFIG.fetch(%q(LIBRUBY_SO))'
libruby.so.1.9.1

So I guess mystery solved.



来源:https://stackoverflow.com/questions/13273773/ruby-1-9-3-teeny-version

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!