gpt4 book ai didi

c - 其中错误消息 ArgumentError : no id given comes from when calling method_missing

转载 作者:行者123 更新时间:2023-11-30 18:53:39 27 4
gpt4 key购买 nike

当您使用第一个参数作为 '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:没有给出id。它从哪里来?

最佳答案

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");
}
// ...
}

关于c - 其中错误消息 ArgumentError : no id given comes from when calling method_missing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32361688/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com