Module: RFunk::Match

Defined in:
lib/rfunk/match.rb,
lib/rfunk/match/error.rb,
lib/rfunk/match/pattern.rb

Defined Under Namespace

Classes: Error, Pattern

Instance Method Summary collapse

Instance Method Details

#match(option) {|pattern| ... } ⇒ Object

Yields:

  • (pattern)

Raises:



3
4
5
6
7
8
9
10
11
12
# File 'lib/rfunk/match.rb', line 3

def match(option)
  pattern = RFunk::Match::Pattern.new
  yield(pattern)

  pattern_case = pattern.cases.find { |t| t.first == option.key || t.first == :_ }

  return pattern_case.last.call(option.identity) if pattern_case

  raise RFunk::Match::Error, "Could not match for option '#{option.key}'."
end