Ruby’s default stack size is 1MB (this value I think also depends on the OS you’re using). I have encountered an issue where a method that implements recursion returned a Stack Level Too Deep error message. One might think that this could potentially be an infinite loop (this is where the defined limit helps) but may not apply to all use-cases.
For Ruby > 2.0, one way to override the stack size limit is to add the RUBY_THREAD_VM_STACK_SIZE env variable.
export RUBY_THREAD_VM_STACK_SIZE=2097152
reference: https://chengl.com/ruby-and-java-stack-level