summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-26 10:55:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-26 10:55:47 +0000
commitc30aed0817f86fcd911cdd36a00ffab906cb4843 (patch)
treef66be71b9242ee29c8258202475b63c4ce582bd9 /error.c
parentf79d891aad37ee9b267f431f74ca1e527c396794 (diff)
error.c: receiver kwarg
* error.c (name_err_initialize_options): NameError#initialize accepts receiver. [Feature #14313] * error.c (nometh_err_initialize_options): pass keyword arguments to the super method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/error.c b/error.c
index 1ae4093cb6..7cbbf101e0 100644
--- a/error.c
+++ b/error.c
@@ -1351,6 +1351,8 @@ rb_name_error_str(VALUE str, const char *fmt, ...)
rb_exc_raise(exc);
}
+static VALUE name_err_initialize_options(int argc, VALUE *argv, VALUE self, VALUE options);
+
/*
* call-seq:
* NameError.new([msg, *, name]) -> name_error
@@ -1363,12 +1365,30 @@ rb_name_error_str(VALUE str, const char *fmt, ...)
static VALUE
name_err_initialize(int argc, VALUE *argv, VALUE self)
{
+ VALUE options;
+ argc = rb_scan_args(argc, argv, "*:", NULL, &options);
+ return name_err_initialize_options(argc, argv, self, options);
+}
+
+static VALUE
+name_err_initialize_options(int argc, VALUE *argv, VALUE self, VALUE options)
+{
+ ID keywords[1];
+ VALUE values[numberof(keywords)];
VALUE name;
VALUE iseqw = Qnil;
+ int i;
+ keywords[0] = id_receiver;
+ rb_get_kwargs(options, keywords, 0, numberof(values), values);
name = (argc > 1) ? argv[--argc] : Qnil;
rb_call_super(argc, argv);
rb_ivar_set(self, id_name, name);
+ for (i = 0; i < numberof(keywords); ++i) {
+ if (values[i] != Qundef) {
+ rb_ivar_set(self, keywords[i], values[i]);
+ }
+ }
{
const rb_execution_context_t *ec = GET_EC();
rb_control_frame_t *cfp =
@@ -1416,6 +1436,8 @@ name_err_local_variables(VALUE self)
return vars;
}
+static VALUE nometh_err_initialize_options(int argc, VALUE *argv, VALUE self, VALUE options);
+
/*
* call-seq:
* NoMethodError.new([msg, *, name [, args [, priv]]]) -> no_method_error
@@ -1429,9 +1451,17 @@ name_err_local_variables(VALUE self)
static VALUE
nometh_err_initialize(int argc, VALUE *argv, VALUE self)
{
+ VALUE options;
+ argc = rb_scan_args(argc, argv, "*:", NULL, &options);
+ return nometh_err_initialize_options(argc, argv, self, options);
+}
+
+static VALUE
+nometh_err_initialize_options(int argc, VALUE *argv, VALUE self, VALUE options)
+{
VALUE priv = (argc > 3) && (--argc, RTEST(argv[argc])) ? Qtrue : Qfalse;
VALUE args = (argc > 2) ? argv[--argc] : Qnil;
- name_err_initialize(argc, argv, self);
+ name_err_initialize_options(argc, argv, self, options);
rb_ivar_set(self, id_args, args);
rb_ivar_set(self, id_private_call_p, RTEST(priv) ? Qtrue : Qfalse);
return self;