Sha256: 07ddc4f8d3823721e90fee690d77a410afc518e2c1e126a6f1e8d113af3acfac

Contents?: true

Size: 789 Bytes

Versions: 3

Compression:

Stored size: 789 Bytes

Contents

# frozen_string_literal: true

module RaaP
  module Value
    class Intersection < BasicObject
      def initialize(type, size:)
        @type = type
        @children = type.types.map { |t| Type.new(t).pick(size: size) }
        @size = size
      end

      def inspect
        "#<intersection @type=#{@type.to_s.inspect} @size=#{@size.inspect}>"
      end

      def class
        Intersection
      end

      def method_missing(name, *args, **kwargs, &block)
        @children.each do |child|
          if BindCall.respond_to?(child, name)
            return child.__send__(name, *args, **kwargs, &block)
          end
        end
      end

      def respond_to?(...)
        @children.any? do |type|
          BindCall.respond_to?(type, ...)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
raap-0.3.0 lib/raap/value/intersection.rb
raap-0.2.0 lib/raap/value/intersection.rb
raap-0.1.0 lib/raap/value/intersection.rb