问题
I know it's possible to get the Ruby version (e.g. "1.9.3") via the RUBY_VERSION constant. However, I want to know how to go about determining the exact version (e.g.: "1.9.3-p0"). The reason is that there is a bug that was not fixed in earlier versions of Ruby 1.9.3 that is working in later versions, and I want some code in a gem I'm working on to account for this.
回答1:
There is a RUBY_PATCHLEVEL constant as well. So you can get your version string as
"#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
回答2:
At least in the newest Ruby (2.3.0), there is also a RUBY_DESCRIPTION constant:
RUBY_DESCRIPTION
# => "ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]"
来源:https://stackoverflow.com/questions/11819525/programmatically-getting-full-ruby-version