# Buggy code
def get_env_patch(
    venv: str,
    language_version: str,
) -> PatchesT:
    patches: PatchesT = (
        ("GEM_HOME", os.path.join(venv, "gems")),
        ("GEM_PATH", UNSET),
        ("BUNDLE_IGNORE_CONFIG", "1"),
    )
    if language_version == "system":
        patches += (
            (
                "PATH",
                (
                    os.path.join(venv, "gems", "bin"),
                    os.pathsep,
                    Var("PATH"),
                ),
            ),
        )
    else:  # pragma: win32 no cover
        patches += (
            ("RBENV_ROOT", venv),
            ("RBENV_VERSION", language_version),
            (
                "PATH",
                (
                    os.path.join(venv, "gems", "bin"),
                    os.pathsep,
                    os.path.join(venv, "shims"),
                    os.pathsep,
                    os.path.join(venv, "bin"),
                    os.pathsep,
                    Var("PATH"),
                ),
            ),
        )
    return patches


# Traceback (pre_commit.util.CalledProcessError)
### version information

```
pre-commit version: 2.8.2
sys.version:
    3.8.2 (default, Jul  7 2020, 11:55:37) 
    [Clang 11.0.3 (clang-1103.0.32.62)]
sys.executable: /Users/abuxton/.pyenv/versions/3.8.2/bin/python3.8
os.name: posix
sys.platform: darwin
```

### error information

```
An unexpected error has occurred: CalledProcessError: command: ('/usr/local/bin/bash', '/Users/abuxton/.rbenv/shims/gem', 'build', 'mdl.gemspec')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    rbenv: version `default' is not installed (set by RBENV_VERSION environment variable)
    
```

```
Traceback (most recent call last):
  File "/Users/abuxton/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/Users/abuxton/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pre_commit/main.py", line 375, in main
    return run(args.config, store, args)
  File "/Users/abuxton/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pre_commit/commands/run.py", line 388, in run
    install_hook_envs(hooks, store)
  File "/Users/abuxton/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pre_commit/repository.py", line 206, in install_hook_envs
    _hook_install(hook)
  File "/Users/abuxton/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pre_commit/repository.py", line 82, in _hook_install
    lang.install_environment(
  File "/Users/abuxton/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pre_commit/languages/ruby.py", line 130, in install_environment
    helpers.run_setup_cmd(
  File "/Users/abuxton/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pre_commit/languages/helpers.py", line 52, in run_setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir)
  File "/Users/abuxton/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/local/bin/bash', '/Users/abuxton/.rbenv/shims/gem', 'build', 'mdl.gemspec')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    rbenv: version `default' is not installed (set by RBENV_VERSION environment variable)
```


# Fixed code
def get_env_patch(
    venv: str,
    language_version: str,
) -> PatchesT:
    patches: PatchesT = (
        ("GEM_HOME", os.path.join(venv, "gems")),
        ("GEM_PATH", UNSET),
        ("BUNDLE_IGNORE_CONFIG", "1"),
    )
    if language_version == "system":
        patches += (
            (
                "PATH",
                (
                    os.path.join(venv, "gems", "bin"),
                    os.pathsep,
                    Var("PATH"),
                ),
            ),
        )
    else:  # pragma: win32 no cover
        patches += (
            ("RBENV_ROOT", venv),
            (
                "PATH",
                (
                    os.path.join(venv, "gems", "bin"),
                    os.pathsep,
                    os.path.join(venv, "shims"),
                    os.pathsep,
                    os.path.join(venv, "bin"),
                    os.pathsep,
                    Var("PATH"),
                ),
            ),
        )
    if language_version not in {"system", "default"}:  # pragma: win32 no cover
        patches += (("RBENV_VERSION", language_version),)

    return patches