result = [41, 9, -9, 2, 31, 32, 12, -1] result = result.sort { |a, b| a <=> b } puts result #OUTPUT: -9 -1 2 9 12 31 32 41