Sha256: aedb2c8a849f8e0c0535bcd604a4508a783751f3db99d26d9ab2d9ab1c416784

Contents?: true

Size: 535 Bytes

Versions: 2

Compression:

Stored size: 535 Bytes

Contents

# frozen_string_literal: true

require "dry/matcher"

# rubocop:disable Style/CaseEquality
module Dry
  class Matcher
    PatternMatch = proc do |value, patterns|
      if patterns.empty?
        value
        # rubocop:disable Lint/DuplicateBranch
      elsif value.is_a?(::Array) && patterns.any? { |p| p === value[0] }
        value
      elsif patterns.any? { |p| p === value }
        # rubocop:enable Lint/DuplicateBranch
        value
      else
        Undefined
      end
    end
  end
end
# rubocop:enable Style/CaseEquality

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-matcher-1.0.0 lib/dry/matcher/match.rb
dry-matcher-0.10.0 lib/dry/matcher/match.rb