From 41242ee46a6cb2ece856feb680d14a3a74cbcf9f Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 1 Feb 2004 16:57:47 +0000 Subject: * lib/pp.rb (Struct#pretty_print): make it 1.8 style. (Numeric#pretty_print, FalseClass#pretty_print) (TrueClass#pretty_print, Module#pretty_print): fix pp for objects with instance variables. [ruby-talk:91157] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/pp.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/pp.rb') diff --git a/lib/pp.rb b/lib/pp.rb index c366e25932..a9491f62d2 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -309,7 +309,7 @@ end class Struct def pretty_print(q) - q.object_group(self) { + q.group(1, '#') { self.members.each {|member| q.text "," unless q.first? q.breakable @@ -440,6 +440,14 @@ end } } +[Numeric, FalseClass, TrueClass, Module].each {|c| + c.class_eval { + def pretty_print(q) + q.text inspect + end + } +} + if __FILE__ == $0 require 'test/unit' @@ -534,6 +542,10 @@ if __FILE__ == $0 result = PP.pp(a, '') assert_equal("#{a.inspect}\n", result) assert_match(/\A#\n\z/m, result) + a = 1 + a.instance_eval { @a = nil } + result = PP.pp(a, '') + assert_equal("#{a.inspect}\n", result) end def test_to_s_without_iv @@ -562,7 +574,7 @@ if __FILE__ == $0 def test_struct a = S.new(1,2) a.b = a - assert_equal("#>\n", PP.pp(a, '')) + assert_equal("#>\n", PP.pp(a, '')) end def test_object -- cgit v1.2.3