class Yadriggy::PrettyPrinter

Pretty printer for Ruby

Attributes

printer[R]

@return [Printer] a {Printer} object.

Public Class Methods

ast_to_s(an_ast) click to toggle source

Obtains the string representation of the given AST.

@param [ASTree|ASTnode] an_ast the AST. @return [String] the string representation of the AST.

# File lib/yadriggy/pretty_print.rb, line 13
def self.ast_to_s(an_ast)
  pp = PrettyPrinter.new(Printer.new)
  pp.print(an_ast).printer.output
end
new(printer) click to toggle source

@param [Printer] printer

Calls superclass method Yadriggy::Checker::new
# File lib/yadriggy/pretty_print.rb, line 22
def initialize(printer)
  super()
  @printer = printer
end

Public Instance Methods

empty_params?(params_ast) click to toggle source

@param [Parameters] params_ast a parameter list. @return [Boolean] true if the given parameter list is empty.

# File lib/yadriggy/pretty_print.rb, line 324
def empty_params?(params_ast)
  params_ast.params.empty? && params_ast.optionals.empty? &&
    params_ast.rest_of_params.nil? &&
    params_ast.params_after_rest.empty? && params_ast.keywords.empty? &&
    params_ast.rest_of_keywords.nil? && params_ast.block_param.nil?
end
print(an_ast) click to toggle source

Prints a given AST by {#printer}. @param [ASTree|ASTnode] an_ast the AST. @return [PrettyPrinter] the `self` object.

print_arguments(args_ast, block_arg, block, is_cmd, no_empty_paren=true) click to toggle source

Prints an argument list.

@param [Array<ASTnode>] args_ast an argument list. @param [ASTnode] block_arg a block argument. @param [ASTnode] block a block. @param [Boolean] is_cmd true if opening/closing parentheses are not written

(true if the arguments are for a command).

@param [Boolean] no_empty_paren true if `()` is not printed when an argument list is empty. @return [void]

print_each(array, first) click to toggle source

@api private

print_hash_elements(hash_ast) click to toggle source
print_list(array, first) { |e| ... } click to toggle source

@api private

print_parameters(params_ast) click to toggle source

@api private