module Qo::PatternMatchers::Branching::ClassMethods
Class methods to extend the including class with
@author baweaver @since 1.0.0
Public Instance Methods
register_branch(branch)
click to toggle source
Registers a branch to a pattern matcher.
This defines a method on the pattern matcher matching the `name` of the branch. If the name is `where`, the pattern matcher will now be given a method called `where` with which to match with.
When called, this will either ammend a matcher to the list of matchers or set a default matcher if the branch happens to be a default.
@param branch [Branch]
Branch object to register with a pattern matcher
# File lib/qo/pattern_matchers/branching.rb, line 34 def register_branch(branch) define_method(branch.name) do |*conditions, **keyword_conditions, &function| qo_matcher = Qo::Matchers::Matcher.new('and', conditions, keyword_conditions) branch_matcher = branch.create_matcher( qo_matcher, destructure: @destructure, &function ) if branch.default? @default = branch_matcher else @matchers << branch_matcher end end end