-1

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?

4

1 回答 1

2

raise_method_missing()确实引发了该参数错误:

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");
    }
    // ...
}
于 2015-09-02T19:44:36.817 回答