Class: PatternMatch::PatternSetDeconstructor
- Inherits:
-
PatternDeconstructor
- Object
- Pattern
- PatternElement
- PatternDeconstructor
- PatternMatch::PatternSetDeconstructor
- Defined in:
- lib/pattern-match/experimental.rb
Instance Attribute Summary
Attributes inherited from Pattern
Instance Method Summary collapse
-
#initialize(klass, *subpatterns) ⇒ PatternSetDeconstructor
constructor
A new instance of PatternSetDeconstructor.
- #match(vals) ⇒ Object
Methods inherited from PatternElement
Methods inherited from Pattern
#!@, #&, #ancestors, #append, #directly_quantified?, #inspect, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #validate, #vars, #|
Methods included from PatternMatch::Pattern::Backtrackable
Constructor Details
#initialize(klass, *subpatterns) ⇒ PatternSetDeconstructor
Returns a new instance of PatternSetDeconstructor.
140 141 142 143 |
# File 'lib/pattern-match/experimental.rb', line 140 def initialize(klass, *subpatterns) super(*subpatterns) @klass = klass end |
Instance Method Details
#match(vals) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/pattern-match/experimental.rb', line 145 def match(vals) super do |val| next false unless val.kind_of?(@klass) members = val.to_a next false unless subpatterns.length <= members.length members.permutation(subpatterns.length).find do |perm| cont = nil if callcc {|c| cont = c; perm.zip(subpatterns).all? {|i, pat| pat.match([i]) } } save_choice_point(cont) true else false end end end end |