Sha256: f642b2093e47256a0b13be0f6e0a0b812e055f871bd4ed7303ebc6a743b3ce51

Contents?: true

Size: 828 Bytes

Versions: 65

Compression:

Stored size: 828 Bytes

Contents

# frozen_string_literal: true

class Code
  class Type
    class Or < Type
      attr_reader :left, :right

      def initialize(left, right)
        @left = left
        @right = right
      end

      def valid?(argument)
        valid_for?(expected: left, actual: argument) ||
          valid_for?(expected: right, actual: argument)
      end

      def min_arguments
        [min_arguments_of(left), min_arguments_of(right)].min
      end

      def max_arguments
        left_max_arguments = max_arguments_of(left)
        right_max_arguments = max_arguments_of(right)

        if left_max_arguments.nil? || right_max_arguments.nil?
          nil
        else
          [left_max_arguments, right_max_arguments].max
        end
      end

      def name
        "(#{left.name} | #{right.name})"
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
code-ruby-1.1.3 lib/code/type/or.rb
code-ruby-1.1.1 lib/code/type/or.rb
code-ruby-1.1.0 lib/code/type/or.rb
code-ruby-1.0.0 lib/code/type/or.rb
code-ruby-0.15.16 lib/code/type/or.rb
code-ruby-0.15.15 lib/code/type/or.rb
code-ruby-0.15.14 lib/code/type/or.rb
code-ruby-0.15.13 lib/code/type/or.rb
code-ruby-0.15.12 lib/code/type/or.rb
code-ruby-0.15.11 lib/code/type/or.rb
code-ruby-0.15.10 lib/code/type/or.rb
code-ruby-0.15.9 lib/code/type/or.rb
code-ruby-0.15.8 lib/code/type/or.rb
code-ruby-0.15.7 lib/code/type/or.rb
code-ruby-0.15.6 lib/code/type/or.rb
code-ruby-0.15.5 lib/code/type/or.rb
code-ruby-0.15.4 lib/code/type/or.rb
code-ruby-0.15.3 lib/code/type/or.rb
code-ruby-0.15.2 lib/code/type/or.rb
code-ruby-0.15.0 lib/code/type/or.rb