summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-20 06:08:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-20 06:08:25 +0000
commit17b3441ac4ad1f10bfc7ed1ab88b14ada9ec3e7d (patch)
treebf5e07f2f8b39dca7872ed712df6a92686d339c6 /class.c
parent9191d9e7dbfe3e110dc9b444db1cef3cec16fd69 (diff)
non-keywords hash
* class.c (rb_scan_args), include/ruby/ruby.h (rb_scan_args_set): return non-keywords elements only in the last hash when keyword arguments are extracted from it, as well as methods defined in ruby level. [ruby-core:82427] [Bug #13830] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/class.c b/class.c
index 7df22d9..364f258 100644
--- a/class.c
+++ b/class.c
@@ -1913,8 +1913,8 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
va_list vargs;
int f_var = 0, f_hash = 0, f_block = 0;
int n_lead = 0, n_opt = 0, n_trail = 0, n_mand;
- int argi = 0;
- VALUE hash = Qnil;
+ int argi = 0, last_idx = -1;
+ VALUE hash = Qnil, last_hash = 0;
if (ISDIGIT(*p)) {
n_lead = *p - '0';
@@ -1965,7 +1965,8 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
hash = rb_check_hash_type(last);
if (!NIL_P(hash)) {
VALUE opts = rb_extract_keywords(&hash);
- if (!hash) argc--;
+ if (!(last_hash = hash)) argc--;
+ else last_idx = argc - 1;
hash = opts ? opts : Qnil;
}
}
@@ -1973,14 +1974,14 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
/* capture leading mandatory arguments */
for (i = n_lead; i-- > 0; ) {
var = va_arg(vargs, VALUE *);
- if (var) *var = argv[argi];
+ if (var) *var = (argi == last_idx) ? last_hash : argv[argi];
argi++;
}
/* capture optional arguments */
for (i = n_opt; i-- > 0; ) {
var = va_arg(vargs, VALUE *);
if (argi < argc - n_trail) {
- if (var) *var = argv[argi];
+ if (var) *var = (argi == last_idx) ? last_hash : argv[argi];
argi++;
}
else {
@@ -1993,7 +1994,11 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
var = va_arg(vargs, VALUE *);
if (0 < n_var) {
- if (var) *var = rb_ary_new4(n_var, &argv[argi]);
+ if (var) {
+ int f_last = (last_idx + 1 == argc - n_trail);
+ *var = rb_ary_new4(n_var-f_last, &argv[argi]);
+ if (f_last) rb_ary_push(*var, last_hash);
+ }
argi += n_var;
}
else {
@@ -2003,7 +2008,7 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
/* capture trailing mandatory arguments */
for (i = n_trail; i-- > 0; ) {
var = va_arg(vargs, VALUE *);
- if (var) *var = argv[argi];
+ if (var) *var = (argi == last_idx) ? last_hash : argv[argi];
argi++;
}
/* capture an option hash - phase 2: assignment */