module RakeCompilerDock
def ruby_cc_version(*requirements)
# => "3.4.1:3.3.7:3.2.6"
RakeCompilerDock.ruby_cc_version(Gem::Requirement.new("~> 3.2"))
# => "3.4.1:3.3.7:3.2.6"
RakeCompilerDock.ruby_cc_version("~> 3.2")
# => "3.4.1:2.7.8"
RakeCompilerDock.ruby_cc_version("2.7", "3.4")
For example:
Note that the returned string will contain versions sorted in descending order.
- a Gem::Requirement object
- a String that can be used as a Gem::Requirement constructor argument
- a String that matches the minor version exactly
where each `requirement` may be:
Returns a valid RUBY_CC_VERSION string for the given requirements,
def ruby_cc_version(*requirements) cross = cross_rubies output = [] if requirements.empty? output += cross.values else requirements.each do |requirement| if cross[requirement] output << cross[requirement] else requirement = Gem::Requirement.new(requirement) unless requirement.is_a?(Gem::Requirement) versions = cross.values.find_all { |v| requirement.satisfied_by?(Gem::Version.new(v)) } raise("No matching ruby version for requirement: #{requirement.inspect}") if versions.empty? output += versions end end end output.uniq.sort.reverse.join(":") end