Class: Filigree::DestructuringPattern
- Inherits:
-
MultipleObjectPattern
- Object
- BasicPattern
- MultipleObjectPattern
- Filigree::DestructuringPattern
- Defined in:
- lib/filigree/match.rb
Overview
A pattern that matches an instance of a class and destructures it so that the values contained by the object may be matched upon.
Instance Method Summary collapse
-
#initialize(klass, *pattern) ⇒ DestructuringPattern
constructor
Create a new destructuring pattern.
-
#match?(object, env) ⇒ Boolean
Test to see if the object is an instance of the appropriate class, and if so destructure it and test it’s values against the sub-pattern elements.
Methods included from AbstractClass
#abstract_method, extended, #install_icvars, #new
Methods inherited from BasicPattern
Constructor Details
#initialize(klass, *pattern) ⇒ DestructuringPattern
Create a new destructuring pattern.
451 452 453 454 |
# File 'lib/filigree/match.rb', line 451 def initialize(klass, *pattern) @klass = klass super(pattern) end |
Instance Method Details
#match?(object, env) ⇒ Boolean
Test to see if the object is an instance of the appropriate class, and if so destructure it and test it’s values against the sub-pattern elements.
464 465 466 |
# File 'lib/filigree/match.rb', line 464 def match?(object, env) object.is_a?(@klass) and super(object.destructure(@pattern.length), env) end |