Skip to content

class PrettyPrint
inherits Reference

This class implements a pretty printing algorithm. It finds line breaks and nice indentations for grouped structure.

References

Class methods

.format(obj, io : IO, width : Int32, newline = "\n", indent = 0)

Pretty prints obj into io with the given width as a limit and starting with the given indentation.

View source

.format(io : IO, width : Int32, newline = "\n", indent = 0

Creates a pretty printer and yields it to the block, appending any output to the given io.

View source

.new(output : IO, maxwidth = 79, newline = "\n", indent = 0)

Creates a new pretty printer that will write to the given output and be capped at maxwidth.

View source

Methods

#breakable(sep = " ")

Appends an element that can turn into a newline if necessary.

View source

#comma

Same as:

text ","
breakable
View source

#fill_breakable(sep = " ")

Similar to #breakable except the decision to break or not is determined individually.

View source

#flush

Outputs any buffered data.

View source

#group(indent = 0, open_obj = "", close_obj = ""

Creates a group of objects. Inside a group all breakable objects are either turned into newlines or are output as is, depending on the available width.

View source

#list(left, elements, right, &) : Nil

Appends a list of elements surrounded by left and right and separated by commas, yielding each element to the given block.

View source

#list(left, elements, right) : Nil

Appends a list of elements surrounded by left and right and separated by commas.

View source

#nest(indent = 1

Increases the indentation for breakables inside the current group.

View source

#surround(left, right, left_break = "", right_break = "", &) : Nil

Appends a group that is surrounded by the given left and right objects, and optionally is surrounded by the given breakable objects.

View source

#text(obj)

Appends a text element.

View source