Skip to content

Instantly share code, notes, and snippets.

@daniel-barrows
Last active October 22, 2018 19:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save daniel-barrows/ca8359b76ad9bb84b37593a9f7b695fc to your computer and use it in GitHub Desktop.
Workaround for ubygems.rb / -rubygems parameter feature abruptly removed from Ruby. See https://bugs.ruby-lang.org/issues/14322
#!/bin/sh
# Copyright:: 2018 Daniel Barrows
# License:: zlib/libpng
# https://gist.github.com/daniel-barrows/ca8359b76ad9bb84b37593a9f7b695fc
#
# Workaround for feature abruptly removed from Ruby.
# See https://bugs.ruby-lang.org/issues/14322
# Leave warn variable empty to not output the deprecation warning.
warn=true
if ruby -e exit 2>&1 \
| grep 'cannot load such file -- ubygems (LoadError)' >/dev/null; then
which sudo >/dev/null 2>&1 && sudo=sudo
ruby_lib_dir="$( ruby -e 'exit 0' 2>&1 | grep 'cannot load such file' \
| sed 's,/rubygems/core_ext.\+,,' )"
if ! [ -z "$warn" ]; then
warning_msg="warn 'WARNING: -rubygems flag is deprecated. Use -rrubygems.'"
fi
printf "#!/usr/bin/env ruby\n%s\nrequire 'rubygems'\n" "$warning_msg" \
| $sudo tee "$ruby_lib_dir/ubygems.rb" > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment