Skip to content

Instantly share code, notes, and snippets.

@pvdb
Last active November 16, 2023 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvdb/119687925234e4bbeb58b561c7fb0044 to your computer and use it in GitHub Desktop.
Save pvdb/119687925234e4bbeb58b561c7fb0044 to your computer and use it in GitHub Desktop.
#!/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