<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def list_(prefix='', ruby=None, runas=None, gem_bin=None):
    '''
    List locally installed gems.

    :param prefix: string :
        Only list gems when the name matches this prefix.
    :param gem_bin: string : None
        Full path to ``gem`` binary to use.
    :param ruby: string : None
        If RVM or rbenv are installed, the ruby version and gemset to use.
        Ignored if ``gem_bin`` is specified.
    :param runas: string : None
        The user to run gem as.

    CLI Example:

    .. code-block:: bash

        salt '*' gem.list
    '''
    cmd = ['list']
    if prefix:
        cmd.append(prefix)
    stdout = _gem(cmd,
                  ruby,
                  gem_bin=gem_bin,
                  runas=runas)
    ret = {}
    for line in salt.utils.itertools.split(stdout, '\n'):
        match = re.match(r'^([^ ]+) \((.+)\)', line)
        if match:
            gem = match.group(1)
            versions = match.group(2).split(', ')
            ret[gem] = versions
    return ret