Class: Steep::AST::Types::Literal

Inherits:
Object
  • Object
show all
Includes:
Helper::NoChild, Helper::NoFreeVariables
Defined in:
lib/steep/ast/types/literal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::NoChild

#each_child, #map_type

Methods included from Helper::NoFreeVariables

#free_variables

Constructor Details

#initialize(value:) ⇒ Literal

Returns a new instance of Literal.



7
8
9
# File 'lib/steep/ast/types/literal.rb', line 7

def initialize(value:)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/steep/ast/types/literal.rb', line 5

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



11
12
13
14
# File 'lib/steep/ast/types/literal.rb', line 11

def ==(other)
  other.is_a?(Literal) &&
    other.value == value
end

#back_typeObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/steep/ast/types/literal.rb', line 38

def back_type
  klass = case value
          when Integer
            Builtin::Integer
          when String
            Builtin::String
          when Symbol
            Builtin::Symbol
          when true
            Builtin::TrueClass
          when false
            Builtin::FalseClass
          else
            raise "Unexpected literal type: #{(_ = value).inspect}"
          end

  Name::Instance.new(name: klass.module_name, args: [])
end

#hashObject



16
17
18
# File 'lib/steep/ast/types/literal.rb', line 16

def hash
  self.class.hash
end

#levelObject



34
35
36
# File 'lib/steep/ast/types/literal.rb', line 34

def level
  [0]
end

#subst(s) ⇒ Object



22
23
24
# File 'lib/steep/ast/types/literal.rb', line 22

def subst(s)
  self
end

#to_sObject



26
27
28
# File 'lib/steep/ast/types/literal.rb', line 26

def to_s
  value.inspect
end