Class: Filigree::BasicPattern
- Extended by:
- AbstractClass
- Defined in:
- lib/filigree/match.rb
Overview
This class provides the basis for all match patterns.
Direct Known Subclasses
Instance Method Summary collapse
-
#as(binding_pattern) ⇒ Object
Wraps this pattern in a BindingPattern, causing the object that this pattern matches to be bound to this name in the with block.
-
#match_pattern_element(pattern_elem, object, env) ⇒ Boolean
Test to see if a single object matches a single pattern, using the given environment to store bindings.
Methods included from AbstractClass
abstract_method, extended, install_icvars, new
Instance Method Details
#as(binding_pattern) ⇒ Object
Wraps this pattern in a Filigree::BindingPattern, causing the object that this pattern matches to be bound to this name in the with block.
273 274 275 |
# File 'lib/filigree/match.rb', line 273 def as(binding_pattern) binding_pattern.tap { |bp| bp.pattern_elem = self } end |
#match_pattern_element(pattern_elem, object, env) ⇒ Boolean
Test to see if a single object matches a single pattern, using the given environment to store bindings.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/filigree/match.rb', line 285 def match_pattern_element(pattern_elem, object, env) case pattern_elem when Class object.is_a?(pattern_elem) when Regexp (object.is_a?(String) and (md = pattern_elem.match(object))).tap do |match| env.send("match_data=", md) if match end when BasicPattern pattern_elem.match?(object, env) else object == pattern_elem end end |