Class: PatternMatch::PatternKeywordArgStyleDeconstructor
- Inherits:
-
PatternDeconstructor
- Object
- Pattern
- PatternElement
- PatternDeconstructor
- PatternMatch::PatternKeywordArgStyleDeconstructor
- Defined in:
- lib/pattern-match/experimental.rb
Instance Attribute Summary
Attributes inherited from Pattern
Instance Method Summary collapse
-
#initialize(klass, checker, getter, *keyarg_subpatterns) ⇒ PatternKeywordArgStyleDeconstructor
constructor
A new instance of PatternKeywordArgStyleDeconstructor.
- #inspect ⇒ Object
- #match(vals) ⇒ Object
Methods inherited from PatternElement
Methods inherited from Pattern
#!@, #&, #ancestors, #append, #directly_quantified?, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #validate, #vars, #|
Methods included from PatternMatch::Pattern::Backtrackable
Constructor Details
#initialize(klass, checker, getter, *keyarg_subpatterns) ⇒ PatternKeywordArgStyleDeconstructor
Returns a new instance of PatternKeywordArgStyleDeconstructor.
86 87 88 89 90 91 92 93 |
# File 'lib/pattern-match/experimental.rb', line 86 def initialize(klass, checker, getter, *keyarg_subpatterns) spec = normalize_keyword_arg(keyarg_subpatterns) super(*spec.values) @klass = klass @checker = checker @getter = getter @spec = spec end |
Instance Method Details
#inspect ⇒ Object
105 106 107 |
# File 'lib/pattern-match/experimental.rb', line 105 def inspect "#<#{self.class.name}: klass=#{@klass.inspect}, spec=#{@spec.inspect}>" end |
#match(vals) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/pattern-match/experimental.rb', line 95 def match(vals) super do |val| next false unless val.kind_of?(@klass) next false unless @spec.keys.all? {|k| val.__send__(@checker, k) } @spec.all? do |k, pat| pat.match([val.__send__(@getter, k)]) rescue false end end end |