Module: MatchingExceptions

Extended by:
MatchingExceptions
Included in:
MatchingExceptions
Defined in:
lib/matching_exceptions.rb,
lib/matching_exceptions/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Instance Method Summary collapse

Instance Method Details

#matches(matching, on: 'message') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/matching_exceptions.rb', line 6

def matches(matching, on: 'message')
  klass = Class.new do
    def self.===(other)
      return false unless other.respond_to?(@method)
      return other.send(@method).include?(@matching) if @matching.is_a?(String)
      return other.send(@method) =~ @matching if @matching.is_a?(Regexp)
      false
    end
  end

  klass.instance_variable_set(:@matching, matching)
  klass.instance_variable_set(:@method, on)
  klass
end