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
-
#add_pattern(new_pat) ⇒ void
Inserts a new pattern in the appropriate place in the patterns list.
-
#Bind(name) ⇒ BindingPattern
Force a name binding.
-
#inherited(klass) ⇒ void
A callback used to pass patterns declared in a parent class to a subclass.
-
#install_icvars(inherited_patterns = Array.new) ⇒ 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.
-
#strict_match(bool) ⇒ void
Tell the visitor that it must raise an exception if no match is found.
-
#strict_match? ⇒ Boolean
Accessor for the strict match member.
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.
188 189 190 191 192 193 194 |
# 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 |
Instance Attribute Details
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
86 87 88 |
# File 'lib/filigree/visitor.rb', line 86 def patterns @patterns end |
Class Method Details
.extended(klass) ⇒ Object
196 197 198 |
# File 'lib/filigree/visitor.rb', line 196 def self.extended(klass) klass.install_icvars end |
Instance Method Details
#add_pattern(new_pat) ⇒ void
This method returns an undefined value.
Inserts a new pattern in the appropriate place in the patterns list.
112 113 114 115 116 117 118 119 120 121 |
# 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 |
#Bind(name) ⇒ BindingPattern
Force a name binding.
93 94 95 |
# File 'lib/filigree/visitor.rb', line 93 def Bind(name) BindingPattern.new(name) end |
#inherited(klass) ⇒ void
This method returns an undefined value.
A callback used to pass patterns declared in a parent class to a subclass.
129 130 131 |
# File 'lib/filigree/visitor.rb', line 129 def inherited(klass) klass.install_icvars(@patterns.clone) end |
#install_icvars(inherited_patterns = Array.new) ⇒ void
This method returns an undefined value.
Install the instance class variables in the including class.
136 137 138 139 140 |
# File 'lib/filigree/visitor.rb', line 136 def install_icvars(inherited_patterns = Array.new) @patterns = inherited_patterns @deferred = Array.new @strict_match = false end |
#Literal(obj) ⇒ LiteralPattern
Force a literal comparison.
102 103 104 |
# File 'lib/filigree/visitor.rb', line 102 def Literal(obj) LiteralPattern.new(obj) end |
#on(*pattern, &block) ⇒ void
This method returns an undefined value.
Define a pattern for this visitor.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# 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 |
#strict_match(bool) ⇒ void
This method returns an undefined value.
Tell the visitor that it must raise an exception if no match is found.
171 172 173 |
# File 'lib/filigree/visitor.rb', line 171 def strict_match(bool) @strict_match = bool end |
#strict_match? ⇒ Boolean
Accessor for the strict match member.
179 180 181 |
# File 'lib/filigree/visitor.rb', line 179 def strict_match? @strict_match end |