Skip to content

Instantly share code, notes, and snippets.

@0x0dea
Created July 1, 2015 10:15
Show Gist options
  • Save 0x0dea/2eef9ab030ed8ef7574a to your computer and use it in GitHub Desktop.
Save 0x0dea/2eef9ab030ed8ef7574a to your computer and use it in GitHub Desktop.
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