Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby 1.9.3 Teeny Version

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?

like image 443
Michael Avatar asked Jan 20 '26 02:01

Michael


1 Answers

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!

like image 145
Gregory Brown Avatar answered Jan 22 '26 15:01

Gregory Brown