summaryrefslogtreecommitdiff
path: root/lib/pp.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-11 07:44:58 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-11 07:44:58 +0000
commitea8990d8670f71d6b1fa3d55086c9f147348452c (patch)
treeca1b8e0866c95d88a16d2422c9993bfcf604c50e /lib/pp.rb
parentce2b7ae509b42886e12d0eedbd54fc8b87f34ff5 (diff)
pp prints a multiple lines string prettier.
* lib/pp.rb (String#pretty_print): Defined to print a string as multiple lines. [ruby-core:76800] [Feature#12664] proposed by Petr Chalupa. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pp.rb')
-rw-r--r--lib/pp.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/pp.rb b/lib/pp.rb
index 9678774b8c..5356b7ce25 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -418,6 +418,21 @@ class Range # :nodoc:
end
end
+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
+
class File < IO # :nodoc:
class Stat # :nodoc:
def pretty_print(q) # :nodoc: