Method: Fear::PatternMatchingApi#match

Defined in:
lib/fear/pattern_matching_api.rb

#match(value) {|matcher| ... } ⇒ any

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Pattern match against given value

Examples:

Fear.match(42) do |m|
  m.case(Integer, :even?.to_proc) { |n| "#{n} is even number" }
  m.case(Integer, :odd?.to_proc) { |n| "#{n} is odd number" }
  m.case(Strings) { |n| "#{n} is a string" }
  m.else { 'unknown' }
end #=> "42 is even number"

Parameters:

  • value (any)

Yield Parameters:

Returns:

  • (any)

81
82
83
# File 'lib/fear/pattern_matching_api.rb', line 81

def match(value, &block)
  matcher(&block).(value)
end