Last active
November 16, 2023 10:09
-
-
Save pvdb/119687925234e4bbeb58b561c7fb0044 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
#!/usr/bin/env ruby -r semantic -r consenter | |
# frozen_string_literal: true | |
# | |
# INSTALLATION | |
# | |
# ln -s ${PWD}/rbenv-upgrade $(brew --prefix)/bin/ | |
# sudo ln -s ${PWD}/rbenv-upgrade /usr/local/bin/ | |
# | |
# rubocop:disable Style/CommandLiteral | |
%x(brew update 1>&2) | |
%x(brew upgrade ruby-build 1>&2) | |
IO.popen('ruby-build --definitions') | |
.map(&:strip) # remove whitespace | |
.grep(Semantic::Version::SemVerRegexp) # grep the semver strings | |
.map(&Semantic::Version.method(:new)) # convert to objects (!) | |
.find_all { |v| v.satisfies?('3') } # only keep 3.x.x semvers | |
.find_all { |v| v.pre.nil? } # remove all pre-releases | |
.group_by { |v| v.to_a.first(2) } # group by (major, minor) | |
.values # only keep grouped lists | |
.map(&:max) # semantic-sort & latest | |
.each_consented('Install ruby %s', all: !STDIN.tty?) do |mri| | |
%x(rbenv install #{mri} 1>&2 < /dev/null) | |
end | |
# rubocop:enable Style/CommandLiteral | |
# That's all Folks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment