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

ruby-changes:28782

From: zzak <ko1@a...>
Date: Mon, 20 May 2013 03:18:02 +0900 (JST)
Subject: [ruby-changes:28782] zzak:r40834 (trunk): * lib/pp.rb: Document PP::ObjectMixin [Fixes GH-312]

zzak	2013-05-20 03:17:51 +0900 (Mon, 20 May 2013)

  New Revision: 40834

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40834

  Log:
    * lib/pp.rb: Document PP::ObjectMixin [Fixes GH-312]

  Modified files:
    trunk/ChangeLog
    trunk/lib/pp.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40833)
+++ ChangeLog	(revision 40834)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon May 20 03:16:52 2013  Zachary Scott  <zachary@z...>
+
+	* lib/pp.rb: Document PP::ObjectMixin [Fixes GH-312]
+
 Sun May 19 23:52:22 2013  Ayumu AIZAWA  <ayumu.aizawa@g...>
 
 	* test/webrick/test_htmlutils.rb: add test for WEBrick::HTMLUtils.
Index: lib/pp.rb
===================================================================
--- lib/pp.rb	(revision 40833)
+++ lib/pp.rb	(revision 40834)
@@ -300,6 +300,34 @@ class PP < PrettyPrint https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L300
     include PPMethods
   end
 
+  # Allows you to implement pretty print in your own class, for example:
+  #     require 'pp'
+  #     
+  #     class Cat
+  #       include PP::ObjectMixin
+  #     
+  #       attr_accessor :name, :age, :color
+  #     
+  #       def initialize name
+  #         @name = name
+  #       end
+  #     
+  #       def pretty_print q
+  #         q.pp_object self
+  #       end
+  #       alias inspect pretty_print_inspect
+  #     
+  #     end
+  #
+  # In order to use this class, try the following:
+  #
+  #     ginger = Cat.new("ginger")
+  #     p ginger
+  #     #=> #<Cat:0x007f8dfb994900 @name="ginger">
+  #     ginger.age = 2
+  #     ginger.color = "red"
+  #     p ginger
+  #     #=> #<Cat:0x007f8dfb994900 @age=2, @color="red", @name="ginger">
   module ObjectMixin
     # 1. specific pretty_print
     # 2. specific inspect

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

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