Method: Fear::Try.matcher

Defined in:
lib/fear/try.rb

.matcher {|| ... } ⇒ Fear::PartialFunction

Build pattern matcher to be used later, despite off Try#match method, id doesn’t apply matcher immanently, but build it instead. Unusually in sake of efficiency it’s better to statically build matcher and reuse it later.

Examples:

matcher =
  Try.matcher do |m|
    m.success(Integer, ->(x) { x > 2 }) { |x| x * 2 }
    m.success(String) { |x| x.to_i * 2 }
    m.failure(ActiveRecord::RecordNotFound) { :err }
    m.else { 'error '}
  end
matcher.call(try)

Yield Parameters:



281
282
283
# File 'lib/fear/try.rb', line 281

def matcher(&matcher)
  Try::PatternMatch.new(&matcher)
end