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.
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.
154 155 156 157 158 159 160 |
# File 'lib/filigree/visitor.rb', line 154 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
162 163 164 |
# File 'lib/filigree/visitor.rb', line 162 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.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/filigree/visitor.rb', line 97 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.
78 79 80 |
# File 'lib/filigree/visitor.rb', line 78 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.
114 115 116 |
# File 'lib/filigree/visitor.rb', line 114 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.
121 122 123 124 |
# File 'lib/filigree/visitor.rb', line 121 def install_icvars(inherited_patterns = Array.new) @patterns = inherited_patterns @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.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/filigree/visitor.rb', line 134 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 { |pattern| pattern.block = block } @deferred.clear else @deferred << mp end end |