From 3b302ea8c95d34d5ef072d7e3b326f28a611e479 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sat, 21 Sep 2019 09:03:36 -0700 Subject: Add Module#ruby2_keywords for passing keywords through regular argument splats This approach uses a flag bit on the final hash object in the regular splat, as opposed to a previous approach that used a VM frame flag. The hash flag approach is less invasive, and handles some cases that the VM frame flag approach does not, such as saving the argument splat array and splatting it later: ruby2_keywords def foo(*args) @args = args bar end def bar baz(*@args) end def baz(*args, **kw) [args, kw] end foo(a:1) #=> [[], {a: 1}] foo({a: 1}, **{}) #=> [[{a: 1}], {}] foo({a: 1}) #=> 2.7: [[], {a: 1}] # and warning foo({a: 1}) #=> 3.0: [[{a: 1}], {}] It doesn't handle some cases that the VM frame flag handles, such as when the final hash object is replaced using Hash#merge, but those cases are probably less common and are unlikely to properly support keyword argument separation. Use ruby2_keywords to handle argument delegation in the delegate library. --- internal.h | 1 + 1 file changed, 1 insertion(+) (limited to 'internal.h') diff --git a/internal.h b/internal.h index bb298d2bfb..7de0077d86 100644 --- a/internal.h +++ b/internal.h @@ -815,6 +815,7 @@ struct RComplex { #define RCOMPLEX_SET_IMAG(cmp, i) RB_OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->imag,(i)) enum ruby_rhash_flags { + RHASH_PASS_AS_KEYWORDS = FL_USER1, /* FL 1 */ RHASH_PROC_DEFAULT = FL_USER2, /* FL 2 */ RHASH_ST_TABLE_FLAG = FL_USER3, /* FL 3 */ #define RHASH_AR_TABLE_MAX_SIZE SIZEOF_VALUE -- cgit v1.2.3