SPOJ Adding Reversed Numbers
While your performance limits may be satisfied by producing your results as they are available, there are also other issues in your code which you should consider altering.

First up, 1-liner solutions are convenient for saving some typing, but often make compromises that affect other aspects of your code. In your case, the 1-liner for reversing the number:


  num.to_s.reverse.to_i



That line takes a number, converts it to a string, and then reverses the string, and then converts the string back to a number.

Note that in each conversion, you need to convert between base-2 and base-10 number systems, and that you need to allocate space for the String, etc. While the following takes more code, it actually does less work:

def reverse_num(num)
  rev = 0
  while num &gt; 0 do
    rev *= 10
    rev += num % 10
    num /= 10
  end
  rev
end


There are no strings in the above, the loop iterates one time for each decimal digit, and well, just works.

A second issue I want to point out is with your line-by-line algorithm. You read an entire line, split on the spaces, and from the list of strings, you create a list of numbers with to_i. You then iterate this list, and sum the reverses.

A much neater solution is to do a map->reduce operation:

sum = input_str.split(' ').map{ |n| reverse_num(n.to_i) }.reduce(:+)


Then you can eliminate the entire rev_add method. The end result is:

cases = gets.chomp.to_i

def valid_numeric_input?(input)
  input.zero?
end

def reverse_num(num)
  rev = 0
  while num &gt; 0 do
    rev *= 10
    rev += num % 10
    num /= 10
  end
  rev
end

valid_numeric_input?(cases)

cases.times do |index|
  input_str = gets.chomp
  sum = input_str.split(' ').map{ |n| reverse_num(n.to_i) }.reduce(:+)
  puts reverse_num(sum)
end