diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/pp.rb | 15 |
2 files changed, 21 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Tue Oct 11 16:38:32 2016 Tanaka Akira <akr@fsij.org> + + * lib/pp.rb (String#pretty_print): Defined to print a string as + multiple lines. + [ruby-core:76800] [Feature#12664] proposed by Petr Chalupa. + Mon Oct 10 15:22:27 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * ruby.c (open_load_file): bind the open fd to an IO instance @@ -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: |