class Filigree::OuterPattern

The class that contains all of the pattern elements passed to a with clause.

Attributes

block[W]
guard[R]

Public Class Methods

new(pattern, guard, block) click to toggle source

Create a new outer pattern with the given pattern elements, guard, and block.

@param [Array<Object>] pattern Pattern elements @param [Proc] guard Guard clause that is tested if the pattern matches @param [Proc] block Block to be evaluated if the pattern matches

Calls superclass method Filigree::MultipleObjectPattern::new
# File lib/filigree/match.rb, line 535
def initialize(pattern, guard, block)
        super(pattern)
        @guard = guard
        @block = block
end

Public Instance Methods

<=>(other) click to toggle source

Specialized version of the bi-directional comparison operator.

@param [BasicPattern] other Right-hand side of the comparison

@return [-1, 0, 1] Value corresponding to less than, equal to, or

greater than the right-hand side pattern.
# File lib/filigree/match.rb, line 514
def <=>(other)
        base_compare(other) do
                comp_res =
                self.pattern.zip(other.pattern).inject(0) do |total, pair|
                        total + (pair.first <=> pair.last)
                end <=> 0

                if comp_res == 0
                        self.guard ? (other.guard ? 0 : 1) : (other.guard ? -1 : comp_res)
                else
                        comp_res
                end
        end
end
call(env, objects = []) click to toggle source

Call the pattern's block, passing the given objects to the block.

@param [Object] env Environment in which to evaluate the block @param [Array<Object>] objects Arguments to the block

# File lib/filigree/match.rb, line 545
def call(env, objects = [])
        if @block then env.instance_exec(*objects, &@block) else nil end
end
match?(objects, env) click to toggle source

Test the objects for equality to the pattern elements.

@param [Object] objects Objects to test pattern elements against @param [Object] env Binding environment

@return [Boolean]

Calls superclass method Filigree::MultipleObjectPattern#match?
# File lib/filigree/match.rb, line 555
def match?(objects, env)
        super && (@guard.nil? or env.instance_exec(&@guard))
end