1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2006-05-13 07:35:50 +00:00
parent a673b24319
commit 55fc4f0c27
2 changed files with 22 additions and 3 deletions

View file

@ -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

View file

@ -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