From 9f58113e4d26f4aa7dfd6e66b7bbf9ce6c1b346d Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Fri, 16 Oct 2026 16:45:38 -0400 Subject: [PATCH] ast: Add Node#deconstruct and fix Node#hash Node#hash is [type, children, class].hash, an Integer, not a String. Node#deconstruct returns [type, *children] for pattern matching, as in ast 2.4.2 and 2.4.3. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01GgkyXKEZWpEFXo6ceA5MSw --- gems/ast/2.4/_test/test.rb | 4 +++- gems/ast/2.4/_test/test.rbs | 1 + gems/ast/2.4/ast.rbs | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gems/ast/2.4/_test/test.rb b/gems/ast/2.4/_test/test.rb index ee5bdca3a..c60d3a3d3 100644 --- a/gems/ast/2.4/_test/test.rb +++ b/gems/ast/2.4/_test/test.rb @@ -5,6 +5,7 @@ def Symbol!(_) end def Array!(_) end def Node!(_) end def Bool!(_) end +def Integer!(_) end # AST::Node @@ -13,7 +14,7 @@ def Bool!(_) end AST::Node.new(:x, [:foo, 42], { y: 1 }) Array! node1.children -String! node1.hash +Integer! node1.hash Symbol! node1.type Bool! node1 == node2 Node! node1.append 42 @@ -24,6 +25,7 @@ def Bool!(_) end Node! node1.to_ast String! node1.to_sexp Array! node1.to_sexp_array +Array! node1.deconstruct Node! node1.updated Node! node1.updated(:foo) Node! node1.updated(:foo, []) diff --git a/gems/ast/2.4/_test/test.rbs b/gems/ast/2.4/_test/test.rbs index 44a0f36f2..a8a9f050c 100644 --- a/gems/ast/2.4/_test/test.rbs +++ b/gems/ast/2.4/_test/test.rbs @@ -4,6 +4,7 @@ module Kernel def Array!: (Array[untyped]) -> void def Node!: (AST::Node) -> void def Bool!: (bool) -> void + def Integer!: (Integer) -> void end class X diff --git a/gems/ast/2.4/ast.rbs b/gems/ast/2.4/ast.rbs index e78fd53e6..7f7a5de24 100644 --- a/gems/ast/2.4/ast.rbs +++ b/gems/ast/2.4/ast.rbs @@ -11,7 +11,7 @@ module AST public attr_reader children: Array[untyped] - attr_reader hash: String + attr_reader hash: Integer attr_reader type: Symbol alias + concat @@ -26,6 +26,8 @@ module AST def concat: (_ToA[untyped] array) -> self + def deconstruct: () -> Array[untyped] + def dup: () -> self def eql?: (untyped other) -> bool