def parse_fd(fd, mode)
      fds = case fd
      when PIPE
        IO.pipe
      when IO
        [fd]
      when Integer
        [IO.new(fd, mode)]
      when String
        [File.open(fd, mode)]
      when nil
        []
      else
        raise ArgumentError
      end

      mode == 'r' ? fds : fds.reverse
    end
def parse_fd(fd, mode)
      fds = case fd
      when PIPE
        IO.pipe
      when IO
        [fd]
      when Integer
        [IO.new(fd, mode)]
      when String
        [File.open(fd, mode)]
      when nil
        []
      else
        raise ArgumentError
      end

      mode == 'r' ? fds : fds.reverse
    end
Return a pair of values (child, mine), which are how the given file
 descriptor should appear to the child and to this process, respectively.
 "mine" is only non-nil in the case of a pipe (in fact, we just return a
 list of length one, since ruby will unpack nils from missing list items).