Suggestion for how to update rubygems & bundler

Below updates (test 2.2 thru ruby-head, should work for older Ruby versions also):
Ruby 2.2 - RG 2.7.8 & bundler 1.16.6, which is included in 2.7.8
Ruby 2.3 thru 2.5 - RG 3.0.2 & bundler 1.17.3
Ruby 2.6 - left as is, RG 3.0.1 & bundler 1.17.2
Ruby head/trunk - left as is, RG 3.0.2 & bundler 2.0.1

before_install:
  # rubygems 2.7.8 and greater include bundler
  - |
    rv="$(ruby -e 'STDOUT.write RUBY_VERSION')";
    if   [ "$rv" \< "2.3" ]; then gem update --system 2.7.8 --no-document
    elif [ "$rv" \< "2.6" ]; then gem update --system --no-document --conservative
    elif [ "$rv" = "2.7.0" ]; then
      lib="$(ruby -e 'STDOUT.write RbConfig::CONFIG["sitelibdir"]')";
      rm -rf $lib/rubygems;
      rm -f  $lib/rubygems.rb $lib/ubygems.rb;
    fi
Imprint