Class: Filigree::BindingPattern
- Inherits:
-
SingleObjectPattern
- Object
- BasicPattern
- SingleObjectPattern
- Filigree::BindingPattern
- Defined in:
- lib/filigree/match.rb
Overview
A pattern that binds a sub-pattern’s matching object to a name in the binding environment.
Instance Attribute Summary collapse
-
#pattern_elem ⇒ Object
writeonly
Sets the attribute pattern_elem.
Attributes inherited from SingleObjectPattern
Instance Method Summary collapse
-
#as(_, _) ⇒ Object
Overridden method to prevent binding BindingPattern objects.
-
#initialize(name, pattern_elem = WildcardPattern.instance) ⇒ BindingPattern
constructor
Create a new binding pattern.
-
#match?(object, env) ⇒ Boolean
Test the object for equality to the pattern element.
- #weight ⇒ Object
Methods included from AbstractClass
#abstract_method, extended, #install_icvars, #new
Methods inherited from BasicPattern
Constructor Details
#initialize(name, pattern_elem = WildcardPattern.instance) ⇒ BindingPattern
Create a new binding pattern.
431 432 433 434 |
# File 'lib/filigree/match.rb', line 431 def initialize(name, pattern_elem = WildcardPattern.instance) @name = name super(pattern_elem) end |
Instance Attribute Details
#pattern_elem=(value) ⇒ Object (writeonly)
Sets the attribute pattern_elem
425 426 427 |
# File 'lib/filigree/match.rb', line 425 def pattern_elem=(value) @pattern_elem = value end |
Instance Method Details
#as(_, _) ⇒ Object
Overridden method to prevent binding BindingPattern objects.
437 438 439 |
# File 'lib/filigree/match.rb', line 437 def as(_, _) raise 'Binding a BindingPattern is not allowed.' end |
#match?(object, env) ⇒ Boolean
Test the object for equality to the pattern element. Binds the object to the binding pattern’s name if it does match.
448 449 450 |
# File 'lib/filigree/match.rb', line 448 def match?(object, env) @pattern_elem.match?(object, env).tap { |match| env.send("#{@name}=", object) if match } end |
#weight ⇒ Object
452 453 454 |
# File 'lib/filigree/match.rb', line 452 def weight @pattern_elem.weight end |