Class: Tapioca::RBI::Rewriters::GroupNodes

Inherits:
Visitor
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/rbi/rewriters/group_nodes.rb

Instance Method Summary collapse

Methods inherited from Visitor

#visit_all

Instance Method Details

#visit(node) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tapioca/rbi/rewriters/group_nodes.rb', line 11

def visit(node)
  return unless node

  case node
  when Tree
    kinds = node.nodes.map(&:group_kind)
    kinds.compact!
    kinds.uniq!

    groups = {}
    kinds.each { |kind| groups[kind] = Group.new(kind) }

    node.nodes.dup.each do |child|
      visit(child)
      child.detach
      groups[child.group_kind] << child
    end

    groups.each { |_, group| node << group }
  end
end