Class: Yoda::Typing::Tree::Case

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

Instance Attribute Summary

Attributes inherited from Base

#context, #tracer

Instance Method Summary collapse

Methods inherited from Base

#build_child, #generator, #infer_child, #initialize, #inspect, #pretty_print, #type

Constructor Details

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

Instance Method Details

#infer_typeType::Type

Returns:

  • (Type::Type)


9
10
11
12
13
14
# File 'lib/yoda/typing/tree/case.rb', line 9

def infer_type
  subject_node, *when_nodes, else_node = node.children
  infer_child(subject_node)
  when_body_nodes = when_nodes.map { |node| node.children.last }
  generator.union_type(*[*when_body_nodes, else_node].compact.map { |node| infer_child(node) })
end

#nodeAST::CaseNode

Returns:



# File 'lib/yoda/typing/tree/case.rb', line 5