crubymri

Where error message ArgumentError: no id given comes from when calling method_missing


When you call method_missing with first parameter as 'string' instead of :symbol you get this cryptic error message:

BasicObject.send(:method_missing, 'any-method')
ArgumentError: no id given
from (pry):3:in `method_missing'

When you look at the source code for method_missing

static VALUE
rb_method_missing(int argc, const VALUE *argv, VALUE obj)
{
    rb_thread_t *th = GET_THREAD();
    raise_method_missing(th, argc, argv, obj, th->method_missing_reason);
    UNREACHABLE;
}

there is nothing with error message ArgumentError: no id given. Where it comes from?


Solution

  • raise_method_missing() does raise that argument error:

    static void
    raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj,
                         int last_call_status)
    {
        // ...
        if (argc == 0 || !SYMBOL_P(argv[0])) {
            rb_raise(rb_eArgError, "no id given");
        }
        // ...
    }