# Buggy code
def install_ruby(ruby, runas=None):
    """
    Install a ruby implementation.

    ruby
        The version of Ruby to install, should match one of the
        versions listed by :py:func:`rbenv.list <salt.modules.rbenv.list>`

    runas
        The user under which to run rbenv. If not specified, then rbenv will be
        run as the user under which Salt is running.

    Additional environment variables can be configured in pillar /
    grains / master:

    .. code-block:: yaml

        rbenv:
          build_env: 'CONFIGURE_OPTS="--no-tcmalloc" CFLAGS="-fno-tree-dce"'

    CLI Example:

    .. code-block:: bash

        salt '*' rbenv.install_ruby 2.0.0-p0
    """
    ruby = re.sub(r"^ruby-", "", ruby)

    env = None
    env_list = []

    if __grains__["os"] in ("FreeBSD", "NetBSD", "OpenBSD"):
        env_list.append("MAKE=gmake")

    if __salt__["config.get"]("rbenv:build_env"):
        env_list.append(__salt__["config.get"]("rbenv:build_env"))
    elif __salt__["config.option"]("rbenv.build_env"):
        env_list.append(__salt__["config.option"]("rbenv.build_env"))

    if env_list:
        env = " ".join(env_list)

    ret = {}
    ret = _rbenv_exec(["install", ruby], env=env, runas=runas, ret=ret)
    if ret["retcode"] == 0:
        rehash(runas=runas)
        return ret["stderr"]
    else:
        # Cleanup the failed installation so it doesn't list as installed
        uninstall_ruby(ruby, runas=runas)
        return False


# Traceback (TypeError)
----------
ID: myuser_ruby
Function: rbenv.installed
Name: 2.3.3
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/var/tmp/.myuser_684964_salt/py2/salt/state.py", line 1843, in call
**cdata['kwargs'])
File "/var/tmp/.myuser_684964_salt/py2/salt/loader.py", line 1795, in wrapper
return f(*args, **kwargs)
File "/var/tmp/.myuser_684964_salt/py2/salt/states/rbenv.py", line 143, in installed
return _check_and_install_ruby(ret, name, default, user=user)
File "/var/tmp/.myuser_684964_salt/py2/salt/states/rbenv.py", line 93, in _check_and_install_ruby
if __salt__['rbenv.install_ruby'](ruby, runas=user):
File "/var/tmp/.myuser_684964_salt/py2/salt/modules/rbenv.py", line 248, in install_ruby
if ret['retcode'] == 0:
TypeError: 'bool' object has no attribute '__getitem__'
Started: 13:47:50.485521
Duration: 3677.38 ms
Changes:

# Fixed code
def install_ruby(ruby, runas=None):
    """
    Install a ruby implementation.

    ruby
        The version of Ruby to install, should match one of the
        versions listed by :py:func:`rbenv.list <salt.modules.rbenv.list>`

    runas
        The user under which to run rbenv. If not specified, then rbenv will be
        run as the user under which Salt is running.

    Additional environment variables can be configured in pillar /
    grains / master:

    .. code-block:: yaml

        rbenv:
          build_env: 'CONFIGURE_OPTS="--no-tcmalloc" CFLAGS="-fno-tree-dce"'

    CLI Example:

    .. code-block:: bash

        salt '*' rbenv.install_ruby 2.0.0-p0
    """
    ruby = re.sub(r"^ruby-", "", ruby)

    env = None
    env_list = []

    if __grains__["os"] in ("FreeBSD", "NetBSD", "OpenBSD"):
        env_list.append("MAKE=gmake")

    if __salt__["config.get"]("rbenv:build_env"):
        env_list.append(__salt__["config.get"]("rbenv:build_env"))
    elif __salt__["config.option"]("rbenv.build_env"):
        env_list.append(__salt__["config.option"]("rbenv.build_env"))

    if env_list:
        env = " ".join(env_list)

    ret = {}
    ret = _rbenv_exec(["install", ruby], env=env, runas=runas, ret=ret)
    if ret is not False and ret["retcode"] == 0:
        rehash(runas=runas)
        return ret["stderr"]
    else:
        # Cleanup the failed installation so it doesn't list as installed
        uninstall_ruby(ruby, runas=runas)
        return False