Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
KeyError.new
[K, R] (?::string msg, ?receiver: R?, ?key: K?) -> ::KeyError[K, R]
KeyError.new(message=nil, receiver: nil, key: nil) → key_error
error.c
View on GitHub ↗
static VALUE
key_err_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE options;
rb_call_super(rb_scan_args(argc, argv, "01:", NULL, &options), argv);
if (!NIL_P(options)) {
ID keywords[2];
VALUE values[numberof(keywords)];
int i;
keywords[0] = id_receiver;
keywords[1] = id_key;
rb_get_kwargs(options, keywords, 0, numberof(values), values);
for (i = 0; i < numberof(values); ++i) {
if (!UNDEF_P(values[i])) {
rb_ivar_set(self, keywords[i], values[i]);
}
}
}
return self;
}
Construct a new KeyError exception with the given message, receiver and key.