summaryrefslogtreecommitdiff
path: root/lib/pp.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-11 12:29:17 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-11 12:29:17 +0000
commitc47f24027a3473fbdf9510cc300565fb1e6f1db8 (patch)
tree8c9773ba66d0c783ebe8b867db5c410fba9a4b17 /lib/pp.rb
parentbfb17752441e7d0106dff08c74a6fcd01131a6f8 (diff)
* pp.rb (ARGF.pretty_print): implemented.
(PP.pp): arguments reordered. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pp.rb')
-rw-r--r--lib/pp.rb38
1 files changed, 24 insertions, 14 deletions
diff --git a/lib/pp.rb b/lib/pp.rb
index 81b06df003..0eb8f28ac6 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -69,10 +69,15 @@ PP#pp to print the object.
((<PrettyPrint>))
== class methods
---- PP.pp(obj[, width[, out]])
+--- PP.pp(obj[, out[, width]])
outputs ((|obj|)) to ((|out|)) in pretty printed format of
((|width|)) columns in width.
+ If ((|out|)) is ommitted, (({$>})) is assumed.
+ If ((|width|)) is ommitted, 79 is assumed.
+
+ PP.pp returns ((|out|)).
+
--- PP.sharing_detection
returns the sharing detection flag as boolean value.
It is false by default.
@@ -116,8 +121,7 @@ PP#pp to print the object.
detected as part of a cycle.
--- pretty_print_instance_variables
- is a method to list instance variables used by the default implementation
- of (({pretty_print})).
+ returns a sorted array of instance variable names.
This method should return an array of names of instance variables as symbols or strings as:
(({[:@a, :@b]})).
@@ -136,7 +140,7 @@ module Kernel
end
class PP < PrettyPrint
- def PP.pp(obj, width=79, out=$>)
+ def PP.pp(obj, out=$>, width=79)
pp = PP.new(out, width)
pp.guard_inspect_key {pp.pp obj}
pp.flush
@@ -434,6 +438,12 @@ class File
end
end
+class << ARGF
+ def pretty_print(pp)
+ pp.text self.to_s
+ end
+end
+
class Object
include PP::ObjectMixin
end
@@ -450,11 +460,11 @@ if __FILE__ == $0
class PPTest < RUNIT::TestCase
def test_list0123_12
- assert_equal("[0, 1, 2, 3]\n", PP.pp([0,1,2,3], 12, ''))
+ assert_equal("[0, 1, 2, 3]\n", PP.pp([0,1,2,3], '', 12))
end
def test_list0123_11
- assert_equal("[0,\n 1,\n 2,\n 3]\n", PP.pp([0,1,2,3], 11, ''))
+ assert_equal("[0,\n 1,\n 2,\n 3]\n", PP.pp([0,1,2,3], '', 11))
end
end
@@ -499,17 +509,17 @@ if __FILE__ == $0
class PPInspectTest < RUNIT::TestCase
def test_hasinspect
a = HasInspect.new(1)
- assert_equal("<inspect:1>\n", PP.pp(a, 79, ''))
+ assert_equal("<inspect:1>\n", PP.pp(a, ''))
end
def test_hasprettyprint
a = HasPrettyPrint.new(1)
- assert_equal("<pretty_print:1>\n", PP.pp(a, 79, ''))
+ assert_equal("<pretty_print:1>\n", PP.pp(a, ''))
end
def test_hasboth
a = HasBoth.new(1)
- assert_equal("<pretty_print:1>\n", PP.pp(a, 79, ''))
+ assert_equal("<pretty_print:1>\n", PP.pp(a, ''))
end
end
@@ -517,32 +527,32 @@ if __FILE__ == $0
def test_array
a = []
a << a
- assert_equal("[[...]]\n", PP.pp(a, 79, ''))
+ assert_equal("[[...]]\n", PP.pp(a, ''))
end
def test_hash
a = {}
a[0] = a
- assert_equal("{0=>{...}}\n", PP.pp(a, 79, ''))
+ assert_equal("{0=>{...}}\n", PP.pp(a, ''))
end
S = Struct.new("S", :a, :b)
def test_struct
a = S.new(1,2)
a.b = a
- assert_equal("#<Struct::S a=1, b=#<Struct::S:...>>\n", PP.pp(a, 79, ''))
+ assert_equal("#<Struct::S a=1, b=#<Struct::S:...>>\n", PP.pp(a, ''))
end
def test_object
a = Object.new
a.instance_eval {@a = a}
- assert_equal(a.inspect + "\n", PP.pp(a, 79, ''))
+ assert_equal(a.inspect + "\n", PP.pp(a, ''))
end
def test_withinspect
a = []
a << HasInspect.new(a)
- assert_equal("[<inspect:[...]>]\n", PP.pp(a, 79, ''))
+ assert_equal("[<inspect:[...]>]\n", PP.pp(a, ''))
end
end