Module: Qo::PublicApi
Overview
The Public API consists of methods that should be openly accessible to the top level Qo namespace, and should not change. It should be used as the subject of Acceptance level tests for the library and should not have its externally facing methods renamed or moved under pain of a look of profound disappointment from the creator.
Instance Method Summary collapse
-
#and(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
(also: #[])
Creates an
andtype query matcher. -
#case(value, &fn) ⇒ Any
Similar to the common case statement of Ruby, except in that it behaves as if
Array#===andHash#===exist in the form of Qo matchers. -
#match(&fn) ⇒ Qo::PatternMatch
A pattern match will try and run all guard block style matchers in sequence until it finds one that "matches".
-
#not(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
Creates a
nottype query matcher. -
#or(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
Creates an
ortype query matcher.
Instance Method Details
#and(*array_matchers, **keyword_matchers) ⇒ Proc[Any] Also known as: []
Creates an and type query matcher. All conditions in this type of matcher
must pass to be considered a "match". It will short-circuit in the case of
a false match.
26 27 28 |
# File 'lib/qo/public_api.rb', line 26 def and(*array_matchers, **keyword_matchers) create_matcher('and', array_matchers, keyword_matchers) end |
#case(value, &fn) ⇒ Any
I refer to the potential 2.6+ features currently being discussed here:
Hash#===- https://bugs.ruby-lang.org/issues/14869Array#===- https://bugs.ruby-lang.org/issues/14916
Similar to the common case statement of Ruby, except in that it behaves
as if Array#=== and Hash#=== exist in the form of Qo matchers.
113 114 115 |
# File 'lib/qo/public_api.rb', line 113 def case(value, &fn) Qo::Matchers::PatternMatch.new(&fn).call(value) end |
#match(&fn) ⇒ Qo::PatternMatch
A pattern match will try and run all guard block style matchers in sequence until it finds one that "matches". Once found, it will pass the target into the associated matcher's block function.
81 82 83 84 85 |
# File 'lib/qo/public_api.rb', line 81 def match(&fn) return proc { false } unless block_given? Qo::Matchers::PatternMatch.new(&fn) end |
#not(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
Creates a not type query matcher. No conditions in this type of matcher
should pass to be considered a "match". It will short-circuit in the case of
a true match.
61 62 63 |
# File 'lib/qo/public_api.rb', line 61 def not(*array_matchers, **keyword_matchers) create_matcher('not', array_matchers, keyword_matchers) end |
#or(*array_matchers, **keyword_matchers) ⇒ Proc[Any]
Creates an or type query matcher. Any conditions in this type of matcher
must pass to be considered a "match". It will short-circuit in the case of
a true match.
45 46 47 |
# File 'lib/qo/public_api.rb', line 45 def or(*array_matchers, **keyword_matchers) create_matcher('or', array_matchers, keyword_matchers) end |