<commit_before>test-ruby () {
  [[ ! -x $1 ]] && { echo "false"; return 1; }
  "$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \
    "puts Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) == \
          Gem::Version.new('$required_ruby_version').to_s.split('.').first(2)" 2>/dev/null
}

setup-ruby-path() {
  local vendor_dir
  local vendor_ruby_current_version
  local vendor_ruby_path
  local usable_ruby_version
  # When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh)
  # also needs to be changed.
  local required_ruby_version="2.6"
  local ruby_exec
  local advice="
If there's no Homebrew Portable Ruby available for your processor:
- install Ruby $required_ruby_version with your system package manager (or rbenv/ruby-build)
- make it first in your PATH
- try again
"

  vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor"
  vendor_ruby_current_version="$vendor_dir/portable-ruby/current"
  vendor_ruby_path="$vendor_ruby_current_version/bin/ruby"

  unset HOMEBREW_RUBY_PATH

  if [[ "$HOMEBREW_COMMAND" == "vendor-install" ]]
  then
    return 0
  fi

  if [[ -x "$vendor_ruby_path" ]]
  then
    HOMEBREW_RUBY_PATH="$vendor_ruby_path"

    if [[ $(readlink "$vendor_ruby_current_version") != "$(<"$vendor_dir/portable-ruby-version")" ]]
    then
      if ! brew vendor-install ruby
      then
        if [[ -n "$HOMEBREW_MACOS" ]]
        then
          odie "Failed to upgrade Homebrew Portable Ruby!"
        else
          odie "Failed to upgrade Homebrew Portable Ruby!$advice"
        fi
      fi
    fi
  else
    if [[ -n "$HOMEBREW_MACOS" ]]
    then
      HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
    else
      IFS=$'\n' # Do word splitting on new lines only
      for ruby_exec in $(which -a ruby) $(PATH=$HOMEBREW_PATH which -a ruby)
      do
        if [[ $(test-ruby "$ruby_exec") == "true" ]]; then
          HOMEBREW_RUBY_PATH=$ruby_exec
          break
        fi<commit_msg>utils/ruby.sh: make code more readable<commit_after>test-ruby () {
  [[ ! -x $1 ]] && { echo "false"; return 1; }
  "$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \
    "puts Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) == \
          Gem::Version.new('$required_ruby_version').to_s.split('.').first(2)" 2>/dev/null
}

setup-ruby-path() {
  local vendor_dir
  local vendor_ruby_path
  local vendor_ruby_latest_version
  local vendor_ruby_current_version
  local usable_ruby_version
  # When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh)
  # also needs to be changed.
  local required_ruby_version="2.6"
  local ruby_exec
  local advice="
If there's no Homebrew Portable Ruby available for your processor:
- install Ruby $required_ruby_version with your system package manager (or rbenv/ruby-build)
- make it first in your PATH
- try again
"

  vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor"
  vendor_ruby_path="$vendor_dir/portable-ruby/current/bin/ruby"
  vendor_ruby_latest_version=$(<"$vendor_dir/portable-ruby-version")
  vendor_ruby_current_version=$(readlink "$vendor_dir/portable-ruby/current")

  unset HOMEBREW_RUBY_PATH

  if [[ "$HOMEBREW_COMMAND" == "vendor-install" ]]
  then
    return 0
  fi

  if [[ -x "$vendor_ruby_path" ]]
  then
    HOMEBREW_RUBY_PATH="$vendor_ruby_path"
    if [[ $vendor_ruby_current_version != $vendor_ruby_latest_version ]]
    then
      if ! brew vendor-install ruby
      then
        if [[ -n "$HOMEBREW_MACOS" ]]
        then
          odie "Failed to upgrade Homebrew Portable Ruby!"
        else
          odie "Failed to upgrade Homebrew Portable Ruby!$advice"
        fi
      fi
    fi
  else
    if [[ -n "$HOMEBREW_MACOS" ]]
    then
      HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
    else
      IFS=$'\n' # Do word splitting on new lines only
      for ruby_exec in $(which -a ruby) $(PATH=$HOMEBREW_PATH which -a ruby)
      do
        if [[ $(test-ruby "$ruby_exec") == "true" ]]; then
          HOMEBREW_RUBY_PATH=$ruby_exec
          break
        fi
{'fraction_non_alphanumeric': 0.12052821128451381, 'fraction_numerical': 0.004321728691476591, 'mean_word_length': 3.277207392197125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7634113', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1417, 'n_words': 314}