Where error message ArgumentError: no id given comes from when calling method_missing
Where error message ArgumentError: no id given comes from when calling method_missing
当您使用第一个参数 'string'
而不是 :symbol
调用 method_missing
时,您会收到这个神秘的错误消息:
BasicObject.send(:method_missing, 'any-method')
ArgumentError: no id given
from (pry):3:in `method_missing'
当您查看 source code 时 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;
}
没有任何错误消息 ArgumentError: no id given
。
它来自哪里?
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");
}
// ...
}
当您使用第一个参数 'string'
而不是 :symbol
调用 method_missing
时,您会收到这个神秘的错误消息:
BasicObject.send(:method_missing, 'any-method')
ArgumentError: no id given
from (pry):3:in `method_missing'
当您查看 source code 时 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;
}
没有任何错误消息 ArgumentError: no id given
。
它来自哪里?
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");
}
// ...
}