Class: Filigree::BasicPattern

Inherits:
Object
  • Object
show all
Extended by:
AbstractClass
Includes:
Comparable
Defined in:
lib/filigree/match.rb

Overview

This class provides the basis for all match patterns.

Instance Method Summary collapse

Methods included from AbstractClass

abstract_method, extended, install_icvars, new

Instance Method Details

#<=>(other) ⇒ Integer

Base implementation of bi-directional comparison for patterns.

Parameters:

  • other (BasicPattern)

    Right-hand side of the comparison

Returns:

  • (Integer)

    Value corresponding to less than, equal to, or greater than the right-hand side pattern.



302
303
304
305
306
# File 'lib/filigree/match.rb', line 302

def <=>(other)
	# This is performed in the non-intuitive order due to
	# higher-priority patterns having lower weights.
	other.weight - self.weight
end

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

Parameters:

  • binding_pattern (BindingPattern)

    Binding pattern containing the name



312
313
314
# File 'lib/filigree/match.rb', line 312

def as(binding_pattern)
	binding_pattern.tap { |bp| bp.pattern_elem = self }
end