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