Merge pull request #10358 from SeekingMeaning/mac-version-named-captures

os/mac/version: use named captures in regex
This commit is contained in:
Seeker 2021-01-19 10:51:52 -08:00 committed by GitHub
commit 152eac333b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,13 +37,17 @@ module OS
def self.version_arch(value)
@all_archs_regex ||= begin
all_archs = Hardware::CPU::ALL_ARCHS.map(&:to_s)
/^((#{Regexp.union(all_archs)})_)?([\w.]+)(-(#{Regexp.union(all_archs)}))?$/
/
^((?<prefix_arch>#{Regexp.union(all_archs)})_)?
(?<version>[\w.]+)
(-(?<suffix_arch>#{Regexp.union(all_archs)}))?$
/x
end
match = @all_archs_regex.match(value)
return [] unless match
version = match[3]
arch = match[2] || match[5]
version = match[:version]
arch = match[:prefix_arch] || match[:suffix_arch]
[version, arch]
end