The stack level is too deep in the_missing method

I have the following Ruby method that specifies the RSpec stack level too strongly, and I'm not sure why - any help is greatly appreciated!

def method_missing(method_name, *args)
  full_method_name = "#{self.class.to_s.downcase}_#{method_name.to_s}"
  respond_to(:full_method_name) ? send(:full_method_name, @options) : super
end

      

+3


source to share


1 answer


When you run into an error stack level too deep

, it usually means that you have incorrectly written your invariant for the recursive method, and the ruby ​​gets stuck recursively by calling the specified method ad infinitum, filling the memory allocated for the stack.

TL; DR; It's an endless loop.



What happens to you, except that you don't recursively call method_missing

explicitly, you call it implicitly. You probably have a method call in method_missing

that doesn't exist
. Check the existence of this method.

In particular, the method respond_to

doesn't exist, I think you mean respond_to?

.

+2


source







All Articles