Class/Module Index [+]

Quicksearch

Reek::Source::SexpNode

Extensions to Sexp to allow CodeParser to navigate the abstract syntax tree more easily.

Public Class Methods

format(expr) click to toggle source
# File lib/reek/source/tree_dresser.rb, line 9
def self.format(expr)
  case expr
  when Sexp then expr.format_ruby
  else expr.to_s
  end
end

Public Instance Methods

deep_copy() click to toggle source
# File lib/reek/source/tree_dresser.rb, line 55
def deep_copy
  YAML::load(YAML::dump(self))
end
each_node(type, ignoring, &blk) click to toggle source
# 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
format_ruby() click to toggle source
# 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
has_type?(type) click to toggle source
# File lib/reek/source/tree_dresser.rb, line 24
def has_type?(type)
  is_language_node? and first == type
end
hash() click to toggle source
# File lib/reek/source/tree_dresser.rb, line 16
def hash
  self.inspect.hash
end
is_language_node?() click to toggle source
# File lib/reek/source/tree_dresser.rb, line 20
def is_language_node?
  first.class == Symbol
end
look_for(target_type, ignoring, &blk) click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.