Sha256: 39d9ff13e8d1ff4777250a888754621099bd08105c3a05d9ce79d53185cd8abf

Contents?: true

Size: 1.21 KB

Versions: 43

Compression:

Stored size: 1.21 KB

Contents

module Steep
  module Subtyping
    class Trace
      attr_reader :array

      def initialize(array: [])
        @array = array
      end

      def interface(sub, sup, &block)
        push :interface, sub, sup, &block
      end

      def method(name, sub, sup, &block)
        push :method, sub, sup, name, &block
      end

      def method_type(name, sub, sup, &block)
        push :method_type, sub, sup, name, &block
      end

      def type(sub, sup, &block)
        push :type, sub, sup, &block
      end

      def push(*xs)
        array << xs
        yield
      ensure
        array.pop
      end

      def add(sup, sub)
        array << [sup, sub]
        yield
      ensure
        array.pop
      end

      def empty?
        array.empty?
      end

      def drop(n)
        self.class.new(array: array.drop(n))
      end

      def size
        array.size
      end

      def +(other)
        self.class.new(array: array + other.array)
      end

      def initialize_copy(source)
        @array = source.array.dup
      end

      def each
        if block_given?
          array.each do |pair|
            yield(*pair)
          end
        else
          enum_for :each
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
steep-0.14.0 lib/steep/subtyping/trace.rb
steep-0.13.0 lib/steep/subtyping/trace.rb
steep-0.12.0 lib/steep/subtyping/trace.rb