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:) ⇒ Tuple

Returns a new instance of Tuple.



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

def initialize(types:)
  @types = types
end

Instance Attribute Details

#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?



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

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

#each_child(&block) ⇒ Object



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

def each_child(&block)
  if block
    types.each(&block)
  else
    types.each
  end
end

#free_variablesObject



30
31
32
33
34
# File 'lib/steep/ast/types/tuple.rb', line 30

def free_variables()
  @fvs ||= each_child.with_object(Set[]) do |type, set| #$ Set[variable]
    set.merge(type.free_variables)
  end
end

#hashObject



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

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

#levelObject



50
51
52
# File 'lib/steep/ast/types/tuple.rb', line 50

def level
  [0] + level_of_children(types)
end

#map_type(&block) ⇒ Object



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

def map_type(&block)
  Tuple.new(types: types.map(&block))
end

#subst(s) ⇒ Object



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

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

#to_sObject



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

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

#with_location(new_location) ⇒ Object



54
55
56
# File 'lib/steep/ast/types/tuple.rb', line 54

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