mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
error.c: KeyError missing keyword arguments
* error.c (key_err_initialize): leave attributes for missing keyword arguments unset, so accessors can tell if it is missing or explicit nil. [Feature #14313] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6b61e99e08
commit
ba4aba0d6c
2 changed files with 6 additions and 7 deletions
9
error.c
9
error.c
|
@ -1692,8 +1692,6 @@ key_err_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
VALUE message;
|
VALUE message;
|
||||||
VALUE options;
|
VALUE options;
|
||||||
VALUE receiver = Qnil;
|
|
||||||
VALUE key = Qnil;
|
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01:", &message, &options);
|
rb_scan_args(argc, argv, "01:", &message, &options);
|
||||||
|
|
||||||
|
@ -1711,16 +1709,13 @@ key_err_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
keywords[1] = id_key;
|
keywords[1] = id_key;
|
||||||
rb_get_kwargs(options, keywords, 0, 2, values);
|
rb_get_kwargs(options, keywords, 0, 2, values);
|
||||||
if (values[0] != Qundef) {
|
if (values[0] != Qundef) {
|
||||||
receiver = values[0];
|
rb_ivar_set(self, id_receiver, values[0]);
|
||||||
}
|
}
|
||||||
if (values[1] != Qundef) {
|
if (values[1] != Qundef) {
|
||||||
key = values[1];
|
rb_ivar_set(self, id_key, values[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_ivar_set(self, id_receiver, receiver);
|
|
||||||
rb_ivar_set(self, id_key, key);
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,15 @@ class TestKeyError < Test::Unit::TestCase
|
||||||
receiver = Object.new
|
receiver = Object.new
|
||||||
error = KeyError.new(receiver: receiver)
|
error = KeyError.new(receiver: receiver)
|
||||||
assert_equal(receiver, error.receiver)
|
assert_equal(receiver, error.receiver)
|
||||||
|
error = KeyError.new
|
||||||
|
assert_raise(ArgumentError) {error.receiver}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_key
|
def test_key
|
||||||
error = KeyError.new(key: :key)
|
error = KeyError.new(key: :key)
|
||||||
assert_equal(:key, error.key)
|
assert_equal(:key, error.key)
|
||||||
|
error = KeyError.new
|
||||||
|
assert_raise(ArgumentError) {error.key}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_receiver_and_key
|
def test_receiver_and_key
|
||||||
|
|
Loading…
Reference in a new issue