Class: Filigree::OuterPattern

Inherits:
MultipleObjectPattern show all
Defined in:
lib/filigree/match.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AbstractClass

#abstract_method, extended, #install_icvars, #new

Methods inherited from BasicPattern

#as, #match_pattern_element

Constructor Details

#initialize(pattern, guard, block) ⇒ OuterPattern

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

Parameters:

  • pattern (Array<Object>)

    Pattern elements

  • guard (Proc)

    Guard clause that is tested if the pattern matches

  • block (Proc)

    Block to be evaluated if the pattern matches



419
420
421
422
423
# File 'lib/filigree/match.rb', line 419

def initialize(pattern, guard, block)
	super(pattern)
	@guard = guard
	@block = block
end

Instance Attribute Details

#block=(value) ⇒ Object (writeonly)

Sets the attribute block

Parameters:

  • value

    the value to set the attribute block to.



411
412
413
# File 'lib/filigree/match.rb', line 411

def block=(value)
  @block = value
end

Instance Method Details

#call(env, objects = []) ⇒ Object

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

Parameters:

  • env (Object)

    Environment in which to evaluate the block

  • objects (Array<Object>) (defaults to: [])

    Arguments to the block



429
430
431
# File 'lib/filigree/match.rb', line 429

def call(env, objects = [])
	if @block then env.instance_exec(*objects, &@block) else nil end
end

#match?(objects, env) ⇒ Boolean

Test the objects for equality to the pattern elements.

Parameters:

  • objects (Object)

    Objects to test pattern elements against

  • env (Object)

    Binding environment

Returns:

  • (Boolean)


439
440
441
# File 'lib/filigree/match.rb', line 439

def match?(objects, env)
	super && (@guard.nil? or env.instance_exec(&@guard))
end