module Filigree::Visitor::ClassMethods
Class Methods #
Attributes
Public Class Methods
# File lib/filigree/visitor.rb, line 196 def self.extended(klass) klass.install_icvars end
Public Instance Methods
Force a name binding.
@param [Symbol] name Name to bind to
@return [BindingPattern]
# File lib/filigree/visitor.rb, line 93 def Bind(name) BindingPattern.new(name) end
Force a literal comparison.
@param [Object] obj Object
to be comapred against
@return [LiteralPattern]
# File lib/filigree/visitor.rb, line 102 def Literal(obj) LiteralPattern.new(obj) end
Inserts a new pattern in the appropriate place in the patterns list.
@param [OuterPattern] new_pat New pattern to add
@return [void]
# File lib/filigree/visitor.rb, line 112 def add_pattern(new_pat) @patterns.each_with_index do |old_pat, index| if new_pat > old_pat @patterns.insert(index, new_pat) return end end @patterns << new_pat end
A callback used to pass patterns declared in a parent class to a subclass.
@param [Class] klass Subclass
@return [void]
# File lib/filigree/visitor.rb, line 129 def inherited(klass) klass.install_icvars(@patterns.clone) end
Install the instance class variables in the including class.
@return [void]
# File lib/filigree/visitor.rb, line 136 def install_icvars(inherited_patterns = Array.new) @patterns = inherited_patterns @deferred = Array.new @strict_match = false end
Used to generate wildcard and binding patterns.
# File lib/filigree/visitor.rb, line 188 def method_missing(name, *args) if args.empty? if name == :_ then WildcardPattern.instance else BindingPattern.new(name) end else super(name, *args) end end
Define a pattern for this visitor.
@see match Pattern matching description
@param [Object] pattern List of pattern elements @param [Proc] block Block to be executed when the pattern is matched
@return [void]
# File lib/filigree/visitor.rb, line 150 def on(*pattern, &block) guard = if pattern.last.is_a?(Proc) then pattern.pop end pattern = Filigree::wrap_pattern_elements(pattern) add_pattern (mp = OuterPattern.new(pattern, guard, block)) if block @deferred.each { |deferred_pattern| deferred_pattern.block = block } @deferred.clear else @deferred << mp end end
Tell the visitor that it must raise an exception if no match is found.
@param [Boolean] bool Raise an exception or not.
@return [void]
# File lib/filigree/visitor.rb, line 171 def strict_match(bool) @strict_match = bool end
Accessor for the strict match member.
@return [Boolean] The value of the class's @strict_match
instance variable.
# File lib/filigree/visitor.rb, line 179 def strict_match? @strict_match end