Class: Noaidi::Matchmaker
- Inherits:
-
Object
- Object
- Noaidi::Matchmaker
- Defined in:
- lib/noaidi/matchmaker.rb
Constant Summary collapse
- NoMatchError =
Class.new(StandardError)
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#initialize(block) ⇒ Matchmaker
constructor
A new instance of Matchmaker.
Constructor Details
#initialize(block) ⇒ Matchmaker
Returns a new instance of Matchmaker.
13 14 15 |
# File 'lib/noaidi/matchmaker.rb', line 13 def initialize(block) @branches = process_block(block) end |
Instance Method Details
#call(value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/noaidi/matchmaker.rb', line 17 def call(value) values = Array(value) @branches.each do |matchers, block| return block.call(*meaningful_values(matchers, values)) if matches?(matchers, values) end raise NoMatchError, "No match for #{@values.inspect}" end |