Project

General

Profile

Actions

Feature #12664

closed

Multiline pretty-printing of multiline strings

Added by pitr.ch (Petr Chalupa) over 8 years ago. Updated about 8 years ago.

Status:
Closed
Target version:
-
[ruby-core:76800]

Description

With following addition

class String
  def pretty_print(q)
    lines = self.lines
    if lines.size > 1
      q.group(0, '', '') do
        q.seplist(lines, lambda { q.text ' +'; q.breakable }) do |v|
          q.pp v
        end
      end
    else
      q.text inspect
    end
  end
end

a multiline String will print as follows

[9] pry(main)> pp "bundler.rb"=> "module Bundler\n  BundlerError = Class.new(Exception)\n  def self.setup\n  end\nend\n"
{"bundler.rb"=>
  "module Bundler\n" +
  "  BundlerError = Class.new(Exception)\n" +
  "  def self.setup\n" +
  "  end\n" +
  "end\n"}
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0