Class: Qo::Matcher
- Inherits:
-
Object
- Object
- Qo::Matcher
- Defined in:
- lib/qo/matcher.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#call(match_target) ⇒ type
(also: #===, #[])
You can directly call a matcher as well, much like a Proc, using one of call, ===, or [].
-
#initialize(type, *array_matchers, **keyword_matchers) ⇒ Matcher
constructor
A new instance of Matcher.
-
#to_proc ⇒ Proc
Converts a Matcher to a proc for use in querying, such as:.
Constructor Details
#initialize(type, *array_matchers, **keyword_matchers) ⇒ Matcher
Returns a new instance of Matcher.
3 4 5 6 7 |
# File 'lib/qo/matcher.rb', line 3 def initialize(type, *array_matchers, **keyword_matchers) @match_method = get_match_method(type) @array_matchers = array_matchers @keyword_matchers = keyword_matchers end |
Instance Method Details
#call(match_target) ⇒ type Also known as: ===, []
You can directly call a matcher as well, much like a Proc, using one of call, ===, or []
28 29 30 |
# File 'lib/qo/matcher.rb', line 28 def call(match_target) self.to_proc.call(match_target) end |
#to_proc ⇒ Proc
Converts a Matcher to a proc for use in querying, such as:
data.select(&Qo[...])
14 15 16 17 18 19 20 |
# File 'lib/qo/matcher.rb', line 14 def to_proc if @array_matchers.empty? match_against_hash(@keyword_matchers) else match_against_array(@array_matchers) end end |