Class: Filigree::OuterPattern
- Inherits:
-
MultipleObjectPattern
- Object
- BasicPattern
- MultipleObjectPattern
- Filigree::OuterPattern
- Defined in:
- lib/filigree/match.rb
Overview
The that contains all of the pattern elements passed to a with clause.
Instance Attribute Summary collapse
-
#block ⇒ Object
writeonly
Sets the attribute block.
Instance Method Summary collapse
-
#call(env, objects = []) ⇒ Object
Call the pattern’s block, passing the given objects to the block.
-
#initialize(pattern, guard, block) ⇒ OuterPattern
constructor
Create a new outer pattern with the given pattern elements, guard, and block.
-
#match?(objects, env) ⇒ Boolean
Test the objects for equality to the pattern elements.
Methods included from AbstractClass
#abstract_method, extended, #install_icvars, #new
Methods inherited from BasicPattern
Constructor Details
#initialize(pattern, guard, block) ⇒ OuterPattern
Create a new outer pattern with the given pattern elements, guard, and block.
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
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.
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.
439 440 441 |
# File 'lib/filigree/match.rb', line 439 def match?(objects, env) super && (@guard.nil? or env.instance_exec(&@guard)) end |