Find indices of first pair of numbers that sums to zero
The problem can be solved in less than quadratic time. Sort the elements by absolute value, then search for consecutive elements that sum up to zero.

def two_sum(nums)
    temp = nums.map.with_index { |x, i| [x, i] }
    temp.sort_by! { |x| x[0].abs }
    for x in temp.zip(temp.rotate)
        if x[0][0] + x[1][0] == 0
            return [x[0][1], x[1][1]]
        end
    end
    return nil
end