module RubbyCop::AST::Traversal
Provides methods for traversing an AST
. Does not transform an AST
; for that, use Parser::AST::Processor. Override methods to perform custom processing. Remember to call `super` if you want to recursively process descendant nodes.
Constants
- MANY_CHILD_NODES
- NO_CHILD_NODES
- ONE_CHILD_NODE
- SECOND_CHILD_ONLY
Public Instance Methods
on_block(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 148 def on_block(node) children = node.children child = children[0] send(:"on_#{child.type}", child) # can be send, zsuper... on_args(children[1]) return unless (child = children[2]) send(:"on_#{child.type}", child) end
on_case(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 157 def on_case(node) node.children.each do |child| send(:"on_#{child.type}", child) if child end nil end
on_casgn(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 71 def on_casgn(node) children = node.children if (child = children[0]) # always const??? send(:"on_#{child.type}", child) end return unless (child = children[2]) send(:"on_#{child.type}", child) end
on_class(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 80 def on_class(node) children = node.children child = children[0] # always const??? send(:"on_#{child.type}", child) if (child = children[1]) send(:"on_#{child.type}", child) end return unless (child = children[2]) send(:"on_#{child.type}", child) end
on_const(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 66 def on_const(node) return unless (child = node.children[0]) send(:"on_#{child.type}", child) end
on_def(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 91 def on_def(node) children = node.children on_args(children[1]) return unless (child = children[2]) send(:"on_#{child.type}", child) end
on_defs(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 116 def on_defs(node) children = node.children child = children[0] send(:"on_#{child.type}", child) on_args(children[2]) return unless (child = children[3]) send(:"on_#{child.type}", child) end
on_if(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 125 def on_if(node) children = node.children child = children[0] send(:"on_#{child.type}", child) if (child = children[1]) send(:"on_#{child.type}", child) end return unless (child = children[2]) send(:"on_#{child.type}", child) end
on_op_asgn(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 108 def on_op_asgn(node) children = node.children child = children[0] send(:"on_#{child.type}", child) child = children[2] send(:"on_#{child.type}", child) end
on_send(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 98 def on_send(node) node.children.each_with_index do |child, i| next if i == 1 send(:"on_#{child.type}", child) if child end nil end
Also aliased as: on_csend
on_while(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 136 def on_while(node) children = node.children child = children[0] send(:"on_#{child.type}", child) return unless (child = children[1]) send(:"on_#{child.type}", child) end
walk(node)
click to toggle source
# File lib/rubbycop/ast/traversal.rb, line 10 def walk(node) return if node.nil? send(:"on_#{node.type}", node) nil end