Class: Synvert::Core::Rewriter::WithinScope
- Defined in:
- lib/synvert/core/rewriter/scope/within_scope.rb
Overview
WithinScope finds out nodes which match rules, then change its scope to matching node.
Instance Method Summary collapse
-
#initialize(instance, rules, options = { recursive: true }, &block) ⇒ WithinScope
constructor
Initialize a scope.
-
#process ⇒ Object
Find out the matching nodes.
Constructor Details
#initialize(instance, rules, options = { recursive: true }, &block) ⇒ WithinScope
Initialize a scope
12 13 14 15 16 17 |
# File 'lib/synvert/core/rewriter/scope/within_scope.rb', line 12 def initialize(instance, rules, = { recursive: true }, &block) @instance = instance @rules = rules @options = @block = block end |
Instance Method Details
#process ⇒ Object
Find out the matching nodes. It checks the current node and iterates all child nodes, then run the block code with each matching node.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/synvert/core/rewriter/scope/within_scope.rb', line 21 def process current_node = @instance.current_node return unless current_node matching_nodes = find_matching_nodes(current_node) @instance.process_with_node current_node do matching_nodes.each do |matching_node| @instance.process_with_node matching_node do @instance.instance_eval(&@block) end end end end |