Sha256: 24e2308fa7404a382613c03c12117d088e104e5c18fa0bf39c14af311f955a35

Contents?: true

Size: 1.38 KB

Versions: 26

Compression:

Stored size: 1.38 KB

Contents

module Steep
  module AST
    module Types
      class Record
        attr_reader :location
        attr_reader :elements

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

        def ==(other)
          other.is_a?(Record) && other.elements == elements
        end

        def hash
          self.class.hash ^ elements.hash
        end

        alias eql? ==

        def subst(s)
          self.class.new(location: location,
                         elements: elements.transform_values {|type| type.subst(s) })
        end

        def to_s
          strings = elements.keys.sort.map do |key|
            "#{key.inspect} => #{elements[key]}"
          end
          "{ #{strings.join(", ")} }"
        end

        def free_variables()
          @fvs ||= Set.new.tap do |set|
            elements.each_value do |type|
              set.merge(type.free_variables)
            end
          end
        end

        include Helper::ChildrenLevel

        def each_child(&block)
          if block
            elements.each_value(&block)
          else
            elements.each_value
          end
        end

        def level
          [0] + level_of_children(elements.values)
        end

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
steep-1.7.0.dev.2 lib/steep/ast/types/record.rb
steep-1.7.0.dev.1 lib/steep/ast/types/record.rb
steep-1.6.0 lib/steep/ast/types/record.rb
steep-1.6.0.pre.4 lib/steep/ast/types/record.rb
steep-1.6.0.pre.3 lib/steep/ast/types/record.rb
steep-1.6.0.pre.2 lib/steep/ast/types/record.rb
steep-1.6.0.pre.1 lib/steep/ast/types/record.rb
steep-1.5.3 lib/steep/ast/types/record.rb
steep-1.5.2 lib/steep/ast/types/record.rb
steep-1.5.1 lib/steep/ast/types/record.rb
steep-1.5.0 lib/steep/ast/types/record.rb
steep-1.5.0.pre.6 lib/steep/ast/types/record.rb
steep-1.5.0.pre.5 lib/steep/ast/types/record.rb
steep-1.5.0.pre.4 lib/steep/ast/types/record.rb
steep-1.5.0.pre.3 lib/steep/ast/types/record.rb
steep-1.5.0.pre.2 lib/steep/ast/types/record.rb
steep-1.5.0.pre.1 lib/steep/ast/types/record.rb
steep-1.4.0 lib/steep/ast/types/record.rb
steep-1.4.0.dev.5 lib/steep/ast/types/record.rb
steep-1.4.0.dev.4 lib/steep/ast/types/record.rb