Extensions to Sexp to allow CodeParser to navigate the abstract syntax tree more easily.
# File lib/reek/source/tree_dresser.rb, line 55 def deep_copy YAML::load(YAML::dump(self)) end
# File lib/reek/source/tree_dresser.rb, line 28 def each_node(type, ignoring, &blk) if block_given? look_for(type, ignoring, &blk) else result = [] look_for(type, ignoring) {|exp| result << exp} result end end
# File lib/reek/source/tree_dresser.rb, line 51 def format_ruby return self[0].to_s unless Array === self Ruby2Ruby.new.process(deep_copy) end
# File lib/reek/source/tree_dresser.rb, line 24 def has_type?(type) is_language_node? and first == type end
# File lib/reek/source/tree_dresser.rb, line 16 def hash self.inspect.hash end
# File lib/reek/source/tree_dresser.rb, line 20 def is_language_node? first.class == Symbol end
Carries out a depth-first traversal of this syntax tree, yielding every Sexp of type target_type. The traversal ignores any node whose type is listed in the Array ignoring.
# File lib/reek/source/tree_dresser.rb, line 43 def look_for(target_type, ignoring, &blk) each do |elem| if Sexp === elem then elem.look_for(target_type, ignoring, &blk) unless ignoring.include?(elem.first) end end blk.call(self) if first == target_type end
Generated with the Darkfish Rdoc Generator 2.