Class: Qo::GuardBlockMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/qo/guard_block_matcher.rb

Constant Summary collapse

IDENTITY =
-> v { v }

Instance Method Summary collapse

Methods inherited from Matcher

#call

Constructor Details

#initialize(*array_matchers, **keyword_matchers, &fn) ⇒ GuardBlockMatcher

Returns a new instance of GuardBlockMatcher.



5
6
7
8
9
# File 'lib/qo/guard_block_matcher.rb', line 5

def initialize(*array_matchers, **keyword_matchers, &fn)
  @fn = fn || IDENTITY

  super('and', *array_matchers, **keyword_matchers)
end

Instance Method Details

#to_procObject



11
12
13
14
15
16
17
# File 'lib/qo/guard_block_matcher.rb', line 11

def to_proc
  -> match_target {
    return [false, false] unless super[match_target]

    [true, @fn.call(match_target)]
  }
end