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