diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-02-01 16:57:47 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-02-01 16:57:47 +0000 |
| commit | d3ec8e3e3fb3023d52e7c4fe6925113e21171fda (patch) | |
| tree | 64f011c1693a462cca6007caa02e729167ed6aef /lib | |
| parent | adf015d4c49b33296f2c986772f4303acf5c0c35 (diff) | |
| download | ruby-d3ec8e3e3fb3023d52e7c4fe6925113e21171fda.tar.gz ruby-d3ec8e3e3fb3023d52e7c4fe6925113e21171fda.tar.xz ruby-d3ec8e3e3fb3023d52e7c4fe6925113e21171fda.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@5607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pp.rb | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -309,7 +309,7 @@ end class Struct def pretty_print(q) - q.object_group(self) { + q.group(1, '#<struct ' + self.class.name, '>') { 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#<Object.*>\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("#<Struct::S a=1, b=#<Struct::S:...>>\n", PP.pp(a, '')) + assert_equal("#<struct Struct::S a=1, b=#<Struct::S:...>>\n", PP.pp(a, '')) end def test_object |
