Module: Hashira::Analysis::TypeWalk

Defined in:
lib/hashira/analysis/type_walk.rb

Class Method Summary collapse

Class Method Details

.descend(node, stack, roots) ⇒ Object



19
20
21
# File 'lib/hashira/analysis/type_walk.rb', line 19

def descend(node, stack, roots, &)
  (node ? node.compact_child_nodes : []).each { each(it, stack, roots:, &) }
end

.each(node, stack = [], roots: nil) {|node, full| ... } ⇒ Object

Yields:

  • (node, full)


10
11
12
13
14
15
# File 'lib/hashira/analysis/type_walk.rb', line 10

def each(node, stack = [], roots: nil, &)
  return descend(node, stack, roots, &) unless type?(node)
  full = Syntax.anchor(stack, Syntax.segments(node.constant_path), roots)
  yield(node, full)
  descend(node.body, stack + [full], roots, &)
end

.type?(node) ⇒ Boolean

Returns:

  • (Boolean)


17
# File 'lib/hashira/analysis/type_walk.rb', line 17

def type?(node) = node.is_a?(Prism::ClassNode) || node.is_a?(Prism::ModuleNode)