[前][次][番号順一覧][スレッド一覧]

ruby-changes:44318

From: akr <ko1@a...>
Date: Tue, 11 Oct 2016 16:45:03 +0900 (JST)
Subject: [ruby-changes:44318] akr:r56391 (trunk): pp prints a multiple lines string prettier.

akr	2016-10-11 16:44:58 +0900 (Tue, 11 Oct 2016)

  New Revision: 56391

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56391

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/pp.rb
Index: lib/pp.rb
===================================================================
--- lib/pp.rb	(revision 56390)
+++ lib/pp.rb	(revision 56391)
@@ -418,6 +418,21 @@ class Range # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L418
   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:
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56390)
+++ ChangeLog	(revision 56391)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct 11 16:38:32 2016  Tanaka Akira  <akr@f...>
+
+	* 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@r...>
 
 	* ruby.c (open_load_file): bind the open fd to an IO instance

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]