module SyntaxTree::WithScope

WithScope is a module intended to be included in classes inheriting from Visitor. The module overrides a few visit methods to automatically keep track of local variables and arguments defined in the current scope. Example usage:

class MyVisitor < Visitor
  include WithScope

  def visit_ident(node)
    # Check if we're visiting an identifier for an argument, a local
    # variable or something else
    local = current_scope.find_local(node)

    if local.type == :argument
      # handle identifiers for arguments
    elsif local.type == :variable
      # handle identifiers for variables
    else
      # handle other identifiers, such as method names
    end
  end
end