Counting numbers whose digits all go up or down
To make Ruby internally use a loop instead of an Array you may want to use 1.upto(10 ** x) that is an Enumerator.  

But I doubt the "HUGE array" is the performance issue here.


First of all Ruby says to do total = .count{ ... } instead of total = 0; .each{ total += 1 if ... }
Then do this thing only once and store in a variable t = i.to_s.split("").sort -- x2 faster
Then use .chars instead of .split("") -- x4 faster


Then conversions between Integer and String seem to be unnecessary:

def total_nums x
  return 0 if x == nil
  return 1 if x == 0

  1.upto(10 ** x).count do |i|
    s = i.to_s.chars
    t = s.sort
    s == t || s == t.reverse
  end
end


Note: probably you want either return 0 if x == 0 or start the loop from 0, not 1.