Class: Yoda::Typing::Tree::HashTree

Inherits:
Base
  • Object
show all
Defined in:
lib/yoda/typing/tree/hash_tree.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_typeTypes::Type

Returns:



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

def infer_type
  hash = node.contents.each_with_object({}) do |node, memo|
    case node.type
    when :pair
      case node.key.type
      when :sym
        memo[node.key.value.to_sym] = infer_child(node.value)
      when :str
        memo[node.key.value.to_s] = infer_child(node.value)
      else
        # TODO: Support other key types.
      end
    when :kwsplat
      infer_child(node.content)
      # TODO: merge infered result
    end
  end

  generator.record_type(hash)
end

#nodeAST::HashNode

Returns:



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