Class: YaEnum::Matcher
- Inherits:
-
Object
- Object
- YaEnum::Matcher
- Defined in:
- lib/ya_enum/matcher.rb
Defined Under Namespace
Classes: NonExhaustiveMatch
Instance Method Summary collapse
-
#initialize(all_variants:) ⇒ Matcher
constructor
A new instance of Matcher.
- #match_on(variant) ⇒ Object
- #on(a_case, &block) ⇒ Object
Constructor Details
#initialize(all_variants:) ⇒ Matcher
Returns a new instance of Matcher.
3 4 5 6 |
# File 'lib/ya_enum/matcher.rb', line 3 def initialize(all_variants:) @cases = [] @all_variants = all_variants end |
Instance Method Details
#match_on(variant) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ya_enum/matcher.rb', line 12 def match_on(variant) ensure_all_variants_handled! match = cases.detect do |a_case, _block| a_case === variant end if match match.last.call end end |
#on(a_case, &block) ⇒ Object
8 9 10 |
# File 'lib/ya_enum/matcher.rb', line 8 def on(a_case, &block) cases << [a_case, block] end |