Class: Filigree::MultipleObjectPattern
- Inherits:
-
BasicPattern
- Object
- BasicPattern
- Filigree::MultipleObjectPattern
- Extended by:
- AbstractClass
- Defined in:
- lib/filigree/match.rb
Overview
An abstract class that matches multiple objects to multiple patterns.
Direct Known Subclasses
Instance Attribute Summary collapse
- #pattern ⇒ Array<BasicPattern> readonly
Instance Method Summary collapse
-
#base_compare(other) ⇒ Integer
A wrapper method to sort MultipleObjectPattern objects by their arity.
-
#initialize(pattern) ⇒ MultipleObjectPattern
constructor
Create a new pattern with multiple elements.
-
#match?(objects, env) ⇒ Boolean
Test multiple objects against multiple pattern elements.
Methods included from AbstractClass
abstract_method, extended, install_icvars, new
Methods inherited from BasicPattern
Constructor Details
#initialize(pattern) ⇒ MultipleObjectPattern
Create a new pattern with multiple elements.
465 466 467 |
# File 'lib/filigree/match.rb', line 465 def initialize(pattern) @pattern = pattern end |
Instance Attribute Details
#pattern ⇒ Array<BasicPattern> (readonly)
460 461 462 |
# File 'lib/filigree/match.rb', line 460 def pattern @pattern end |
Instance Method Details
#base_compare(other) ⇒ Integer
A wrapper method to sort MultipleObjectPattern objects by their arity.
476 477 478 479 480 481 482 |
# File 'lib/filigree/match.rb', line 476 def base_compare(other) if self.pattern.length == other.pattern.length yield else self.pattern.length - other.pattern.length end end |
#match?(objects, env) ⇒ Boolean
Test multiple objects against multiple pattern elements.
489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/filigree/match.rb', line 489 def match?(objects, env) if objects.length == @pattern.length @pattern.zip(objects).each do |pattern_elem, object| return false unless pattern_elem.match?(object, env) end true else (@pattern.length == 1 and @pattern.first == WildcardPattern.instance) end end |