From 2d8788e90cd535933c0f444112d465cffc4c71b1 Mon Sep 17 00:00:00 2001 From: S-H-GAMELINKS Date: Thu, 1 Feb 2024 19:50:40 +0900 Subject: [PATCH] Support NODE_ONCE for pattern matching --- compile.c | 1 + test/ruby/test_pattern_matching.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/compile.c b/compile.c index f1dd595e3d..1336982d32 100644 --- a/compile.c +++ b/compile.c @@ -7259,6 +7259,7 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c case NODE_COLON3: case NODE_BEGIN: case NODE_BLOCK: + case NODE_ONCE: CHECK(COMPILE(ret, "case in literal", node)); // (1) if (in_single_pattern) { ADD_INSN1(ret, line_node, dupn, INT2FIX(2)); diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index 8e2806581c..db6ad06b82 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -353,6 +353,14 @@ END end end + assert_block do + a = "abc" + case 'abc' + in /#{a}/o + true + end + end + assert_block do case 0 in ->(i) { i == 0 }