Class: Steep::AST::Types::Tuple

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::ChildrenLevel

#level_of_children

Constructor Details

#initialize(types:, location: nil) ⇒ Tuple

Returns a new instance of Tuple.



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

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#typesObject (readonly)

Returns the value of attribute types.



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

def types
  @types
end

Instance Method Details

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



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

def ==(other)
  other.is_a?(Tuple) &&
    other.types == types
end

#free_variablesObject



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

def free_variables
  types.each.with_object(Set.new) do |type, set|
    set.merge(type.free_variables)
  end
end

#hashObject



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

def hash
  self.class.hash ^ types.hash
end

#levelObject



41
42
43
# File 'lib/steep/ast/types/tuple.rb', line 41

def level
  [0] + level_of_children(types)
end

#subst(s) ⇒ Object



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

def subst(s)
  self.class.new(location: location,
                 types: types.map {|ty| ty.subst(s) })
end

#to_sObject



29
30
31
# File 'lib/steep/ast/types/tuple.rb', line 29

def to_s
  "[#{types.join(", ")}]"
end

#with_location(new_location) ⇒ Object



45
46
47
# File 'lib/steep/ast/types/tuple.rb', line 45

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