diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-08 11:47:39 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-08 11:47:39 +0000 |
commit | 673aa230507d2c0d363dee81de83dab322f9c4ad (patch) | |
tree | 701a721b77875f20883530e22b042a147c0a2d9f /class.c | |
parent | 6def265d793d401f59d57349190fdd1974f166e4 (diff) | |
download | ruby-673aa230507d2c0d363dee81de83dab322f9c4ad.tar.gz |
class.c: rest kwargs
* class.c (rb_get_kwargs): when values is non-null, remove
extracted keywords from the rest keyword argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r-- | class.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -1914,6 +1914,12 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V int i = 0, j; int rest = 0; VALUE missing = Qnil; + st_data_t key; + +#define extract_kwarg(keyword, val) \ + (key = (st_data_t)(keyword), values ? \ + st_delete(rb_hash_tbl_raw(keyword_hash), &key, (val)) : \ + st_lookup(rb_hash_tbl_raw(keyword_hash), key, (val))) if (optional < 0) { rest = 1; @@ -1929,7 +1935,7 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V VALUE keyword = ID2SYM(table[i]); if (keyword_hash) { st_data_t val; - if (st_lookup(rb_hash_tbl_raw(keyword_hash), (st_data_t)keyword, &val)) { + if (extract_kwarg(keyword, &val)) { if (values) values[i] = (VALUE)val; continue; } @@ -1945,7 +1951,7 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V if (optional && keyword_hash) { for (i = 0; i < optional; i++) { st_data_t val; - if (st_lookup(rb_hash_tbl_raw(keyword_hash), ID2SYM(table[required+i]), &val)) { + if (extract_kwarg(ID2SYM(table[required+i]), &val)) { if (values) values[required+i] = (VALUE)val; j++; } @@ -1957,6 +1963,7 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V } } return j; +#undef extract_kwarg } /*! |