Class: Steep::AST::Types::Tuple
- Inherits:
-
Object
- Object
- Steep::AST::Types::Tuple
- Includes:
- Helper::ChildrenLevel
- Defined in:
- lib/steep/ast/types/tuple.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #free_variables ⇒ Object
- #hash ⇒ Object
-
#initialize(types:, location: nil) ⇒ Tuple
constructor
A new instance of Tuple.
- #level ⇒ Object
- #subst(s) ⇒ Object
- #to_s ⇒ Object
- #with_location(new_location) ⇒ Object
Methods included from Helper::ChildrenLevel
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
#location ⇒ Object (readonly)
Returns the value of attribute location.
6 7 8 |
# File 'lib/steep/ast/types/tuple.rb', line 6 def location @location end |
#types ⇒ Object (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_variables ⇒ Object
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 |
#hash ⇒ Object
18 19 20 |
# File 'lib/steep/ast/types/tuple.rb', line 18 def hash self.class.hash ^ types.hash end |
#level ⇒ Object
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_s ⇒ Object
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 |