Если вы на Ма c, вы можете найти файл rbconfig в /Users/<username>/.rubies/ruby-2.6.5/lib/ruby/2.6.0/x86_64-darwin18
или где-то похожем.
Внутри него комментарий гласит:
# The module storing Ruby interpreter configurations on building.
#
# This file was created by mkconfig.rb when ruby was built. It contains
# build information for ruby which is used e.g. by mkmf to build
# compatible native extensions. Any changes made to this file will be
# lost the next time ruby is built.
Получилось Этот файл генерируется скриптом tool/mkconfig.rb
в процессе сборки. Давайте проверим это.
versions = {}
IO.foreach(File.join(srcdir, "version.h")) do |l|
m = /^\s*#\s*define\s+RUBY_(PATCHLEVEL)\s+(-?\d+)/.match(l)
if m
versions[m[1]] = m[2]
break if versions.size == 4
next
end
m = /^\s*#\s*define\s+RUBY_VERSION_(\w+)\s+(-?\d+)/.match(l)
if m
versions[m[1]] = m[2]
break if versions.size == 4
next
end
m = /^\s*#\s*define\s+RUBY_VERSION\s+\W?([.\d]+)/.match(l)
if m
versions['MAJOR'], versions['MINOR'], versions['TEENY'] = m[1].split('.')
break if versions.size == 4
next
end
end
if versions.size != 4
IO.foreach(File.join(srcdir, "include/ruby/version.h")) do |l|
m = /^\s*#\s*define\s+RUBY_API_VERSION_(\w+)\s+(-?\d+)/.match(l)
if m
versions[m[1]] ||= m[2]
break if versions.size == 4
next
end
end
end
%w[MAJOR MINOR TEENY PATCHLEVEL].each do |v|
print " CONFIG[#{v.dump}] = #{(versions[v]||vars[v]).dump}\n"
end
И это логика c для генерации RbConfig::CONFIG['ruby_version']
.
Два файла, на которые ссылаются в этом файле: version.h
и include/ruby/version.h
, которые Вы можете найти интересным.