Stack class in Ruby to calculate maximum number, get the average, pop, push
Your code here is really just wrapping the Array class from the ruby library.  As such, your performance will be exactly the same as just using Array itself.  The array can hold as many items as you can hold in RAM and the performance will be determined by whatever machine you are running on.

The ruby array class is written in C and performs fairly well.  You ask about optimization but you don't given any criteria, so I can't really speculate beyond that.  If you need something that is extremely fast or needs to scale across millions or billions of items, you may want to look at a different language or even a database.

Looking at your code, you have several instances of the pattern if-elsif-else.  The last two are redundant and can be combined.  For example, the max of an array with one item will be the one item, you don't have to break it out.  Likewise for doing the average; you can average a list with one item and you will still get the correct answer

def max ()
    # returning 'puts' is _very_ unusual.  It would be better to return nil, which Array#max would do anyway
    return puts "Error no input" if @stacks.empty?   
    @stacks.max     # the last expression is returned automatically
end

def average()
    return puts"Error no input" if @stacks.empty?

   sum = @stacks.inject(0, :+)
   sum / @stacks.size # note that if you sum an array of integers this way, the final average will also be an integer unless you convert something to a float first
end