Class: Filigree::OuterPattern
- Inherits:
-
MultipleObjectPattern
- Object
- BasicPattern
- MultipleObjectPattern
- Filigree::OuterPattern
- Defined in:
- lib/filigree/match.rb
Overview
The class that contains all of the pattern elements passed to a with clause.
Instance Attribute Summary collapse
-
#block ⇒ Object
writeonly
Sets the attribute block.
-
#guard ⇒ Object
readonly
Returns the value of attribute guard.
Attributes inherited from MultipleObjectPattern
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Specialized version of the bi-directional comparison operator.
-
#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 inherited from MultipleObjectPattern
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.
537 538 539 540 541 |
# File 'lib/filigree/match.rb', line 537 def initialize(pattern, guard, block) super(pattern) @guard = guard @block = block end |
Instance Attribute Details
#block=(value) ⇒ Object (writeonly)
Sets the attribute block
507 508 509 |
# File 'lib/filigree/match.rb', line 507 def block=(value) @block = value end |
#guard ⇒ Object (readonly)
Returns the value of attribute guard.
508 509 510 |
# File 'lib/filigree/match.rb', line 508 def guard @guard end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Specialized version of the bi-directional comparison operator.
516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/filigree/match.rb', line 516 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 = []) ⇒ Object
Call the pattern’s block, passing the given objects to the block.
547 548 549 |
# File 'lib/filigree/match.rb', line 547 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.
557 558 559 |
# File 'lib/filigree/match.rb', line 557 def match?(objects, env) super && (@guard.nil? or env.instance_exec(&@guard)) end |