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.
533 534 535 536 537 |
# File 'lib/filigree/match.rb', line 533 def initialize(pattern, guard, block) super(pattern) @guard = guard @block = block end |
Instance Attribute Details
#block=(value) ⇒ Object (writeonly)
Sets the attribute block
503 504 505 |
# File 'lib/filigree/match.rb', line 503 def block=(value) @block = value end |
#guard ⇒ Object (readonly)
Returns the value of attribute guard.
504 505 506 |
# File 'lib/filigree/match.rb', line 504 def guard @guard end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Specialized version of the bi-directional comparison operator.
512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/filigree/match.rb', line 512 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.
543 544 545 |
# File 'lib/filigree/match.rb', line 543 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.
553 554 555 |
# File 'lib/filigree/match.rb', line 553 def match?(objects, env) super && (@guard.nil? or env.instance_exec(&@guard)) end |