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.
433 434 435 436 |
# File 'lib/filigree/match.rb', line 433 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
427 428 429 |
# File 'lib/filigree/match.rb', line 427 def pattern_elem=(value) @pattern_elem = value end |
Instance Method Details
#as(_, _) ⇒ Object
Overridden method to prevent binding BindingPattern objects.
439 440 441 |
# File 'lib/filigree/match.rb', line 439 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.
450 451 452 |
# File 'lib/filigree/match.rb', line 450 def match?(object, env) @pattern_elem.match?(object, env).tap { |match| env.send("#{@name}=", object) if match } end |
#weight ⇒ Object
454 455 456 |
# File 'lib/filigree/match.rb', line 454 def weight @pattern_elem.weight end |