Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
PrettyPrint.new
# File tmp/rubies/ruby-4.1.0-preview1/lib/prettyprint.rb, line 85
def initialize(output=''.dup, maxwidth=79, newline="\n", &genspace)
@output = output
@maxwidth = maxwidth
@newline = newline
@genspace = genspace || lambda {|n| ' ' * n}
@output_width = 0
@buffer_width = 0
@buffer = []
root_group = Group.new(0)
@group_stack = [root_group]
@group_queue = GroupQueue.new(root_group)
@indent = 0
end
Creates a buffer for pretty printing.
output is an output target. If it is not specified, ” is assumed. It should have a << method which accepts the first argument obj of PrettyPrint#text, the first argument sep of PrettyPrint#breakable, the first argument newline of PrettyPrint.new, and the result of a given block for PrettyPrint.new.
maxwidth specifies maximum line length. If it is not specified, 79 is assumed. However actual outputs may overflow maxwidth if long non-breakable texts are provided.
newline is used for line breaks. “\n” is used if it is not specified.
The block is used to generate spaces. {|width| ‘ ’ * width} is used if it is not given.