'Call the given Ruby and return:
(<version>, <lib-dir>, <site-lib-dir>, <import-dirs>, <gem-dirs>)
TODO: Unicode path issues?'

def _ruby_info_from_ruby(self, ruby, env):

    import process
    info_cmd = 'puts    RUBY_VERSION;    puts    $:'
    argv = [ruby, '-e', info_cmd]
    log.debug("run    `%s    -e    ...'", ruby)
    p = process.ProcessOpen(argv, env=env.get_all_envvars(), stdin=None)
    (stdout, stderr) = p.communicate()
    stdout_lines = stdout.splitlines(0)
    retval = p.returncode
    if retval:
        log.warn('failed    to    determine    Ruby    info:\n        path:    %s\n        retval:    %s\n        stdout:\n%s\n        stderr:\n%s\n', ruby, retval, indent('\n'.join(stdout_lines)), indent(stderr))
    ruby_ver = stdout_lines[0]
    _ver_parts = ruby_ver.split('.', 2)
    short_ver = '.'.join(_ver_parts[:2])
    if (len(_ver_parts) >= 3):
        sub_minor_ver = int(_ver_parts[2])
    else:
        sub_minor_ver = 0
    prefix = dirname(dirname(ruby))
    libdir = join(prefix, 'lib', 'ruby', short_ver)
    sitelibdir = join(prefix, 'lib', 'ruby', 'site_ruby')
    import_path = [normpath(p) for p in stdout_lines[1:]]
    def get_first_gem_dir_candidate():
        gems_dir_part1 = join(prefix, 'lib', 'ruby', 'gems')
        gems_dir_version = join(gems_dir_part1, short_ver)
        if exists(gems_dir_version):
            return join(gems_dir_version, 'gems')
        for i in range((sub_minor_ver + 1)):
            cand_ver = ('%s.%d' % (gems_dir_version, i))
            if exists(cand_ver):
                return join(cand_ver, 'gems')
        return None
    def gem_ver_from_ver_str(ver_str):
        parts = ver_str.split('.')
        try:
            parts = map(int, parts)
        except ValueError:
            return ver_str
        else:
            return tuple(parts)
    gems_dir = get_first_gem_dir_candidate()
    gem_ver_and_dir_from_name = {}
    if gems_dir:
        for dir in glob(join(gems_dir, '*-*')):
            if (not isdir(dir)):
                continue
            m = self._gem_ver_ptn.match(basename(dir))
            if (not m):
                continue
            (name, ver_str) = m.groups()
            gem_ver = gem_ver_from_ver_str(ver_str)
            if (name in gem_ver_and_dir_from_name):
                if (gem_ver > gem_ver_and_dir_from_name[name][0]):
                    gem_ver_and_dir_from_name[name] = (gem_ver, dir)
            else:
                gem_ver_and_dir_from_name[name] = (gem_ver, dir)
    log.debug('ruby    gem    dir    info:    %s', pformat(gem_ver_and_dir_from_name))
    gem_lib_dirs = []
    for (name, (gem_ver, dir)) in sorted(gem_ver_and_dir_from_name.items()):
        gem_lib_dir = join(dir, 'lib')
        if isdir(gem_lib_dir):
            gem_lib_dirs.append(gem_lib_dir)
    return (ruby_ver, libdir, sitelibdir, import_path, gem_lib_dirs)
