Class: PatternMatch::PatternKeywordArgStyleDeconstructor
Instance Attribute Summary
Attributes inherited from Pattern
#next, #parent, #prev
Instance Method Summary
collapse
#quantifier?
Methods inherited from Pattern
#!@, #&, #ancestors, #append, #directly_quantified?, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #validate, #vars, #|
#choice_points
Constructor Details
92
93
94
95
96
97
98
99
|
# File 'lib/pattern-match/experimental.rb', line 92
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
111
112
113
|
# File 'lib/pattern-match/experimental.rb', line 111
def inspect
"#<#{self.class.name}: klass=#{@klass.inspect}, spec=#{@spec.inspect}>"
end
|
#match(vals) ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/pattern-match/experimental.rb', line 101
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
|