-
-
Save 0x0dea/2eef9ab030ed8ef7574a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems/remote_fetcher' | |
require 'rubygems/resolver/api_set' | |
def which_version_can_i_use? gem, ruby_v = Gem::Version.new(RUBY_VERSION) | |
Gem::Resolver::APISet.new | |
.versions(gem) | |
.map { |ver| Gem::Version.new ver[:number] } | |
.sort | |
.reverse_each do |ver| | |
dep = Gem::Dependency.new gem, ver | |
((spec,),), = Gem::SpecFetcher.fetcher.spec_for_dependency dep | |
req = spec.required_ruby_version | |
return ver.version if req.satisfied_by? ruby_v | |
end | |
:/ | |
end | |
p which_version_can_i_use?('diamond_shell') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment