Sha256: 9a6946fe8877d6c11889ed05da09c1cc861f4e8d959e9ae39090004088afef25

Contents?: true

Size: 1.3 KB

Versions: 18

Compression:

Stored size: 1.3 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)
          elements.each_value(&block)
        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

18 entries across 18 versions & 1 rubygems

Version Path
steep-1.3.0.pre.2 lib/steep/ast/types/record.rb
steep-1.3.0.pre.1 lib/steep/ast/types/record.rb
steep-1.2.1 lib/steep/ast/types/record.rb
steep-1.2.0 lib/steep/ast/types/record.rb
steep-1.2.0.pre.1 lib/steep/ast/types/record.rb
steep-1.1.1 lib/steep/ast/types/record.rb
steep-1.1.0 lib/steep/ast/types/record.rb
steep-1.1.0.pre.1 lib/steep/ast/types/record.rb
steep-1.0.2 lib/steep/ast/types/record.rb
steep-1.0.1 lib/steep/ast/types/record.rb
steep-1.0.0 lib/steep/ast/types/record.rb
steep-0.52.2 lib/steep/ast/types/record.rb
steep-0.52.1 lib/steep/ast/types/record.rb
steep-0.52.0 lib/steep/ast/types/record.rb
steep-0.51.0 lib/steep/ast/types/record.rb
steep-0.50.0 lib/steep/ast/types/record.rb
steep-0.49.1 lib/steep/ast/types/record.rb
steep-0.49.0 lib/steep/ast/types/record.rb