Module: Filigree::Visitor::ClassMethods
- Defined in:
- lib/filigree/visitor.rb
Overview
Class Methods #
Instance Attribute Summary collapse
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
Class Method Summary collapse
Instance Method Summary collapse
-
#Bind(name) ⇒ BindingPattern
Force a name binding.
-
#install_icvars ⇒ void
Install the instance class variables in the including class.
-
#Literal(obj) ⇒ LiteralPattern
Force a literal comparison.
-
#method_missing(name, *args) ⇒ Object
Used to generate wildcard and binding patterns.
-
#on(*pattern, &block) ⇒ void
Define a pattern for this visitor.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Used to generate wildcard and binding patterns.
126 127 128 129 130 131 132 |
# File 'lib/filigree/visitor.rb', line 126 def method_missing(name, *args) if args.empty? if name == :_ then WildcardPattern.instance else BindingPattern.new(name) end else super(name, *args) end end |
Instance Attribute Details
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
71 72 73 |
# File 'lib/filigree/visitor.rb', line 71 def patterns @patterns end |
Class Method Details
.extended(klass) ⇒ Object
134 135 136 |
# File 'lib/filigree/visitor.rb', line 134 def self.extended(klass) klass.install_icvars end |
Instance Method Details
#Bind(name) ⇒ BindingPattern
Force a name binding.
78 79 80 |
# File 'lib/filigree/visitor.rb', line 78 def Bind(name) BindingPattern.new(name) end |
#install_icvars ⇒ void
This method returns an undefined value.
Install the instance class variables in the including class.
94 95 96 97 |
# File 'lib/filigree/visitor.rb', line 94 def install_icvars @patterns = Array.new @deferred = Array.new end |
#Literal(obj) ⇒ LiteralPattern
Force a literal comparison.
87 88 89 |
# File 'lib/filigree/visitor.rb', line 87 def Literal(obj) LiteralPattern.new(obj) end |
#on(*pattern, &block) ⇒ void
This method returns an undefined value.
Define a pattern for this visitor.
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/filigree/visitor.rb', line 107 def on(*pattern, &block) guard = if pattern.last.is_a?(Proc) then pattern.pop end @patterns << (mp = OuterPattern.new(pattern, guard, block)) if block @deferred.each { |pattern| pattern.block = block } @deferred.clear else @deferred << mp end end |