Module: EitherResultMatcher

Defined in:
lib/either_result_matcher.rb,
lib/either_result_matcher/matcher.rb,
lib/either_result_matcher/version.rb

Defined Under Namespace

Classes: Matcher

Constant Summary collapse

VERSION =
"0.2.0".freeze

Class Method Summary collapse

Class Method Details

.for(*match_methods) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/either_result_matcher.rb', line 8

def self.for(*match_methods)
  matchers_mod = Module.new do
    match_methods.each do |match_method|
      define_method(match_method) do |*args, &block|
        result = super(*args)

        if block
          MatchEitherResult(result, &block)
        else
          result
        end
      end
    end
  end

  Module.new do
    const_set :Matchers, matchers_mod

    def self.included(klass)
      klass.prepend const_get(:Matchers)
    end
  end
end