[前][次][番号順一覧][スレッド一覧]

ruby-changes:49936

From: nobu <ko1@a...>
Date: Fri, 26 Jan 2018 19:55:49 +0900 (JST)
Subject: [ruby-changes:49936] nobu:r62054 (trunk): error.c: copy keyword arguments

nobu	2018-01-26 19:55:45 +0900 (Fri, 26 Jan 2018)

  New Revision: 62054

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62054

  Log:
    error.c: copy keyword arguments
    
    * error.c (rb_key_err_new): pass arguments all arguments to the
      super method, except for keyword arguments copied to instance
      variables.  [Feature #14313]

  Modified files:
    trunk/error.c
Index: error.c
===================================================================
--- error.c	(revision 62053)
+++ error.c	(revision 62054)
@@ -1690,29 +1690,21 @@ rb_key_err_new(VALUE mesg, VALUE recv, V https://github.com/ruby/ruby/blob/trunk/error.c#L1690
 static VALUE
 key_err_initialize(int argc, VALUE *argv, VALUE self)
 {
-    VALUE message;
     VALUE options;
 
-    rb_scan_args(argc, argv, "01:", &message, &options);
-
-    if (NIL_P(message)) {
-	rb_call_super(0, NULL);
-    }
-    else {
-	rb_call_super(1, &message);
-    }
+    rb_call_super(rb_scan_args(argc, argv, "01:", NULL, &options), argv);
 
     if (!NIL_P(options)) {
 	ID keywords[2];
-	VALUE values[2];
+	VALUE values[numberof(keywords)];
+	int i;
 	keywords[0] = id_receiver;
 	keywords[1] = id_key;
-	rb_get_kwargs(options, keywords, 0, 2, values);
-	if (values[0] != Qundef) {
-	    rb_ivar_set(self, id_receiver, values[0]);
-	}
-	if (values[1] != Qundef) {
-	    rb_ivar_set(self, id_key, values[1]);
+	rb_get_kwargs(options, keywords, 0, numberof(values), values);
+	for (i = 0; i < numberof(values); ++i) {
+	    if (values[i] != Qundef) {
+		rb_ivar_set(self, keywords[i], values[i]);
+	    }
 	}
     }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]