From 7cfe690ac38caa524dd357f5e279f2b91bf3e7e8 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Mon, 10 Jun 2024 09:35:15 -0400 Subject: [PATCH] [TODO: squash] Move `replace_with_multiple` --- lib/rbi/model.rb | 10 ---------- lib/rbi/rewriters/replace_attributes_with_methods.rb | 10 +++++++++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/rbi/model.rb b/lib/rbi/model.rb index 91672606..f6849858 100644 --- a/lib/rbi/model.rb +++ b/lib/rbi/model.rb @@ -42,16 +42,6 @@ def replace(node) self.parent_tree = nil end - sig { params(nodes: T::Enumerable[Node]).void } - def replace_with_multiple(nodes) - tree = parent_tree - raise unless tree - - # Does this work? - nodes.each { |node| tree << node } - detach - end - sig { returns(T.nilable(Scope)) } def parent_scope parent = T.let(parent_tree, T.nilable(Tree)) diff --git a/lib/rbi/rewriters/replace_attributes_with_methods.rb b/lib/rbi/rewriters/replace_attributes_with_methods.rb index b875346e..eff270cb 100644 --- a/lib/rbi/rewriters/replace_attributes_with_methods.rb +++ b/lib/rbi/rewriters/replace_attributes_with_methods.rb @@ -23,7 +23,7 @@ def visit(node) new_methods = convert_to_methods(attr) - child.replace_with_multiple(new_methods) + replace(child, with: new_methods) end end end @@ -131,6 +131,14 @@ def create_setter_method(name, sig, attribute_type, visibility, loc, comments) # comments: comments, ) end + + def replace(node, with:) + tree = node.parent_tree + raise unless tree + + with.each { |node| tree << node } + node.detach + end end end