summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-19 18:17:51 +0000
committerzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-19 18:17:51 +0000
commit18ffba64bdee370edf93de115215d15019e54f17 (patch)
tree8686d91a66b1b9dced9d9dfb5e4771af3ee28b46 /lib
parentdf425a015a6a84cc85fa8c9e37f0e4b8e067a62c (diff)
* lib/pp.rb: Document PP::ObjectMixin [Fixes GH-312]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/pp.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/pp.rb b/lib/pp.rb
index 18cc473509..b7dbef6ca1 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -300,6 +300,34 @@ class PP < PrettyPrint
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