class Filigree::BindingPattern
A pattern that binds a sub-pattern's matching object to a name in the binding environment.
Attributes
pattern_elem[W]
Public Class Methods
new(name, pattern_elem = WildcardPattern.instance)
click to toggle source
Create a new binding pattern.
@param [Symbol] name Name to bind to @param [Object] pattern_elem
Sub-pattern
Calls superclass method
Filigree::SingleObjectPattern::new
# File lib/filigree/match.rb, line 429 def initialize(name, pattern_elem = WildcardPattern.instance) @name = name super(pattern_elem) end
Public Instance Methods
as(_, _)
click to toggle source
Overridden method to prevent binding BindingPattern
objects.
# File lib/filigree/match.rb, line 435 def as(_, _) raise 'Binding a BindingPattern is not allowed.' end
match?(object, env)
click to toggle source
Test the object for equality to the pattern element. Binds the object to the binding pattern's name if it does match.
@param [Object] object Object
to test pattern against @param [Object] env Binding environment
@return [Boolean]
# File lib/filigree/match.rb, line 446 def match?(object, env) @pattern_elem.match?(object, env).tap { |match| env.send("#{@name}=", object) if match } end
weight()
click to toggle source
# File lib/filigree/match.rb, line 450 def weight @pattern_elem.weight end