Class: Yoda::Typing::Tree::Literal

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

#typeObject



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

def type
  type_for_literal_sexp(node.type)
end

#type_for_literal_sexp(sexp_type) ⇒ Types::Base

Parameters:

  • sexp_type (::Symbol, nil)

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/yoda/typing/tree/literal.rb', line 11

def type_for_literal_sexp(sexp_type)
  case sexp_type
  when :dstr, :str, :xstr, :string
    generator.string_type
  when :dsym, :sym
    generator.symbol_type
  when :array, :splat
    generator.array_type
  when :hash
    generator.hash_type
  when :irange, :erange
    generator.range_type
  when :regexp
    generator.regexp_type
  when :true
    generator.true_type
  when :false
    generator.false_type
  when :nil
    generator.nil_type
  when :int
    generator.integer_type
  when :float
    generator.float_type
  when :complex
    generator.numeric_type
  when :rational
    generator.numeric_type
  else
    generator.any_type
  end
end