class Filigree::MultipleObjectPattern
An abstract class that matches multiple objects to multiple patterns.
Attributes
pattern[R]
@return [Array<BasicPattern>]
Public Class Methods
new(pattern)
click to toggle source
Create a new pattern with multiple elements.
@param [Array<Object>] pattern Array
of pattern elements
# File lib/filigree/match.rb, line 465 def initialize(pattern) @pattern = pattern end
Public Instance Methods
base_compare(other) { || ... }
click to toggle source
A wrapper method to sort MultipleObjectPattern
objects by their arity.
@param [BasicPattern] other Right-hand side of the comparison
@return [Integer] Value corresponding to less than, equal to, or
greater than the right-hand side pattern.
# 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)
click to toggle source
Test multiple objects against multiple pattern elements.
@param [Object] objects Object
to test pattern against
@return [Boolean]
# 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