Class: Filigree::BindingPattern

Inherits:
SingleObjectPattern show all
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

Instance Method Summary collapse

Methods included from AbstractClass

#abstract_method, extended, #install_icvars, #new

Methods inherited from BasicPattern

#as, #match_pattern_element

Constructor Details

#initialize(name, pattern_elem = nil) ⇒ BindingPattern

Create a new binding pattern.



360
361
362
363
# File 'lib/filigree/match.rb', line 360

def initialize(name, pattern_elem = nil)
	@name = name
	super(pattern_elem)
end

Instance Attribute Details

#pattern_elemObject

Returns the value of attribute pattern_elem.



354
355
356
# File 'lib/filigree/match.rb', line 354

def pattern_elem
  @pattern_elem
end

Instance Method Details

#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.



372
373
374
375
376
# File 'lib/filigree/match.rb', line 372

def match?(object, env)
	(@pattern_elem.nil? or super).tap do |match|
		env.send("#{@name}=", object) if match
	end
end