def capture(stream)
      #raise "We can only capture STDOUT or STDERR" unless stream == :stdout || stream == :stderr
      begin
        stream = stream.to_s
        eval "$#{stream} = StringIO.new"
        yield
        result = eval("$#{stream}").read
      ensure
        eval("$#{stream} = #{stream.upcase}")
      end

      result
    end
def capture(stream)
      #raise "We can only capture STDOUT or STDERR" unless stream == :stdout || stream == :stderr
      begin
        stream = stream.to_s
        eval "$#{stream} = StringIO.new"
        yield
        result = eval("$#{stream}").read
      ensure
        eval("$#{stream} = #{stream.upcase}")
      end

      result
    end
Capture STDOUT or STDERR to prevent it from being printed.

    capture(:stdout) do
      ...
    end