[ruby-core:77608] [Ruby trunk Feature#12664] Multiline pretty-printing of multiline strings

From: hsbt@...
Date: 2016-10-13 01:49:37 UTC
List: ruby-core #77608
Issue #12664 has been updated by Hiroshi SHIBATA.

Project changed from CommonRuby to Ruby trunk

----------------------------------------
Feature #12664: Multiline pretty-printing of multiline strings
https://bugs.ruby-lang.org/issues/12664#change-60877

* Author: Petr Chalupa
* Status: Closed
* Priority: Normal
* Assignee: Akira Tanaka
----------------------------------------
With following addition

~~~ ruby
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

~~~ text
[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"}
~~~





-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next