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

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/ast/types/literal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location: nil) ⇒ Literal

Returns a new instance of Literal.



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

def initialize(value:, location: nil)
  @location = location
  @value = value
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

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



13
14
15
16
# File 'lib/steep/ast/types/literal.rb', line 13

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

#back_typeObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/steep/ast/types/literal.rb', line 44

def back_type
  klass = case value
          when Integer
            Builtin::Integer
          when String
            Builtin::String
          when Symbol
            Builtin::Symbol
          else
            raise "Unexpected literal type: #{value.inspect}"
          end

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

#free_variablesObject



32
33
34
# File 'lib/steep/ast/types/literal.rb', line 32

def free_variables
  Set.new
end

#hashObject



18
19
20
# File 'lib/steep/ast/types/literal.rb', line 18

def hash
  self.class.hash
end

#levelObject



36
37
38
# File 'lib/steep/ast/types/literal.rb', line 36

def level
  [0]
end

#subst(s) ⇒ Object



24
25
26
# File 'lib/steep/ast/types/literal.rb', line 24

def subst(s)
  self
end

#to_sObject



28
29
30
# File 'lib/steep/ast/types/literal.rb', line 28

def to_s
  value.inspect
end

#with_location(new_location) ⇒ Object



40
41
42
# File 'lib/steep/ast/types/literal.rb', line 40

def with_location(new_location)
  self.class.new(location: new_location)
end