Class: Steep::AST::Types::Record

Inherits:
Object
  • Object
show all
Includes:
Helper::ChildrenLevel
Defined in:
lib/steep/ast/types/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::ChildrenLevel

#level_of_children

Constructor Details

#initialize(elements:, location: nil) ⇒ Record

Returns a new instance of Record.



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

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

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



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

def elements
  @elements
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

Instance Method Details

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



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

def ==(other)
  other.is_a?(Record) && other.elements == elements
end

#free_variablesObject



32
33
34
35
36
# File 'lib/steep/ast/types/record.rb', line 32

def free_variables
  elements.each_value.with_object(Set.new) do |type, set|
    set.merge(type.free_variables)
  end
end

#hashObject



17
18
19
# File 'lib/steep/ast/types/record.rb', line 17

def hash
  self.class.hash ^ elements.hash
end

#levelObject



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

def level
  [0] + level_of_children(elements.values)
end

#subst(s) ⇒ Object



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

def subst(s)
  self.class.new(location: location,
                 elements: elements.transform_values {|type| type.subst(s) })
end

#to_sObject



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

def to_s
  "{ #{elements.map {|key, value| "#{key.inspect} => #{value}" }.join(", ")} }"
end

#with_location(new_location) ⇒ Object



44
45
46
# File 'lib/steep/ast/types/record.rb', line 44

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