Sha256: 510a71a87bf34dd735247eae6eb05bd66a1b6b8cc00c9223a7650e409972f339

Contents?: true

Size: 1.22 KB

Versions: 26

Compression:

Stored size: 1.22 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 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-0.48.0 lib/steep/ast/types/record.rb
steep-0.47.1 lib/steep/ast/types/record.rb
steep-0.47.0 lib/steep/ast/types/record.rb
steep-0.46.0 lib/steep/ast/types/record.rb
steep-0.45.0 lib/steep/ast/types/record.rb
steep-0.44.1 lib/steep/ast/types/record.rb
steep-0.44.0 lib/steep/ast/types/record.rb
steep-0.43.1 lib/steep/ast/types/record.rb
steep-0.43.0 lib/steep/ast/types/record.rb
steep-0.42.0 lib/steep/ast/types/record.rb
steep-0.41.0 lib/steep/ast/types/record.rb
steep-0.40.0 lib/steep/ast/types/record.rb
steep-0.39.0 lib/steep/ast/types/record.rb
steep-0.38.0 lib/steep/ast/types/record.rb
steep-0.37.0 lib/steep/ast/types/record.rb
steep-0.36.0 lib/steep/ast/types/record.rb
steep-0.35.0 lib/steep/ast/types/record.rb
steep-0.34.0 lib/steep/ast/types/record.rb
steep-0.33.0 lib/steep/ast/types/record.rb
steep-0.32.0 lib/steep/ast/types/record.rb