diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-05-13 07:35:50 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-05-13 07:35:50 +0000 |
commit | 55fc4f0c276978c22dd887f11ef23505a83fe007 (patch) | |
tree | 0c08ed15a8cfd302bf24ab1950ee286043ba1967 | |
parent | a673b243194887bd927a4507206612a8deca9136 (diff) | |
download | ruby-55fc4f0c276978c22dd887f11ef23505a83fe007.tar.gz |
* lib/pp.rb (PP.mcall): new method.
(Struct#pretty_print): call Kernel#class and Struct#members even if
overriden.
(Struct#pretty_print_cycle): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/pp.rb | 18 |
2 files changed, 22 insertions, 3 deletions
@@ -1,3 +1,10 @@ +Sat May 13 16:14:05 2006 Tanaka Akira <akr@m17n.org> + + * lib/pp.rb (PP.mcall): new method. + (Struct#pretty_print): call Kernel#class and Struct#members even if + overriden. + (Struct#pretty_print_cycle): ditto. + Thu May 11 18:30:11 2006 GOTOU Yuuzou <gotoyuzo@notwork.org> * ext/openssl/ossl_cipher.c (add_cipher_name_to_ary): should return @@ -83,6 +83,12 @@ class PP < PrettyPrint out end + # :stopdoc: + def PP.mcall(obj, mod, meth, *args, &block) + mod.instance_method(meth).bind(obj).call(*args, &block) + end + # :startdoc: + @sharing_detection = false class << self # Returns the sharing detection flag as a boolean value. @@ -343,8 +349,8 @@ end class Struct def pretty_print(q) - q.group(1, '#<struct ' + self.class.name, '>') { - q.seplist(self.members, lambda { q.text "," }) {|member| + q.group(1, '#<struct ' + PP.mcall(self, Kernel, :class).name, '>') { + q.seplist(PP.mcall(self, Struct, :members), lambda { q.text "," }) {|member| q.breakable q.text member.to_s q.text '=' @@ -357,7 +363,7 @@ class Struct end def pretty_print_cycle(q) - q.text sprintf("#<struct %s:...>", self.class.name) + q.text sprintf("#<struct %s:...>", PP.mcall(self, Kernel, :class).name) end end @@ -496,6 +502,12 @@ if __FILE__ == $0 def test_list0123_11 assert_equal("[0,\n 1,\n 2,\n 3]\n", PP.pp([0,1,2,3], '', 11)) end + + OverriddenStruct = Struct.new("OverriddenStruct", :members, :class) + def test_struct_override_members # [ruby-core:7865] + a = OverriddenStruct.new(1,2) + assert_equal("#<struct Struct::OverriddenStruct members=1, class=2>\n", PP.pp(a, '')) + end end class HasInspect |