* 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
This commit is contained in:
parent
df425a015a
commit
18ffba64bd
@ -1,3 +1,7 @@
|
|||||||
|
Mon May 20 03:16:52 2013 Zachary Scott <zachary@zacharyscott.net>
|
||||||
|
|
||||||
|
* lib/pp.rb: Document PP::ObjectMixin [Fixes GH-312]
|
||||||
|
|
||||||
Sun May 19 23:52:22 2013 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
|
Sun May 19 23:52:22 2013 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
|
||||||
|
|
||||||
* test/webrick/test_htmlutils.rb: add test for WEBrick::HTMLUtils.
|
* test/webrick/test_htmlutils.rb: add test for WEBrick::HTMLUtils.
|
||||||
|
28
lib/pp.rb
28
lib/pp.rb
@ -300,6 +300,34 @@ class PP < PrettyPrint
|
|||||||
include PPMethods
|
include PPMethods
|
||||||
end
|
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
|
module ObjectMixin
|
||||||
# 1. specific pretty_print
|
# 1. specific pretty_print
|
||||||
# 2. specific inspect
|
# 2. specific inspect
|
||||||
|
Loading…
x
Reference in New Issue
Block a user