Class: Yoda::Typing::Tree::ClassTree

Inherits:
Base
  • Object
show all
Defined in:
lib/yoda/typing/tree/class_tree.rb

Instance Attribute Summary

Attributes inherited from Base

#context, #node

Instance Method Summary collapse

Methods inherited from Base

#build_child, #children, #generator, #initialize

Constructor Details

This class inherits a constructor from Yoda::Typing::Tree::Base

Instance Method Details

#infer_namespace_node(node) ⇒ Types::Base

Parameters:

  • node (::AST::Node)

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yoda/typing/tree/class_tree.rb', line 11

def infer_namespace_node(node)
  case node.type
  when :module
    name_node, block_node = node.children
  when :class
    name_node, _, block_node = node.children
  end
  constant_resolver = ConstantResolver.new(context: context, node: name_node)
  type = constant_resolver.resolve_constant_type
  block_context = NamespaceContext.new(objects: [constant_resolver.constant], parent: context, registry: context.registry, receiver: type)

  if block_node
    derive(context: block_context).infer(block_node)
  end

  type
end

#typeObject



5
6
7
# File 'lib/yoda/typing/tree/class_tree.rb', line 5

def type
  infer_namespace_node(node)
end