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:
parent
a673b24319
commit
55fc4f0c27
2 changed files with 22 additions and 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>
|
Thu May 11 18:30:11 2006 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
||||||
|
|
||||||
* ext/openssl/ossl_cipher.c (add_cipher_name_to_ary): should return
|
* ext/openssl/ossl_cipher.c (add_cipher_name_to_ary): should return
|
||||||
|
|
18
lib/pp.rb
18
lib/pp.rb
|
@ -83,6 +83,12 @@ class PP < PrettyPrint
|
||||||
out
|
out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :stopdoc:
|
||||||
|
def PP.mcall(obj, mod, meth, *args, &block)
|
||||||
|
mod.instance_method(meth).bind(obj).call(*args, &block)
|
||||||
|
end
|
||||||
|
# :startdoc:
|
||||||
|
|
||||||
@sharing_detection = false
|
@sharing_detection = false
|
||||||
class << self
|
class << self
|
||||||
# Returns the sharing detection flag as a boolean value.
|
# Returns the sharing detection flag as a boolean value.
|
||||||
|
@ -343,8 +349,8 @@ end
|
||||||
|
|
||||||
class Struct
|
class Struct
|
||||||
def pretty_print(q)
|
def pretty_print(q)
|
||||||
q.group(1, '#<struct ' + self.class.name, '>') {
|
q.group(1, '#<struct ' + PP.mcall(self, Kernel, :class).name, '>') {
|
||||||
q.seplist(self.members, lambda { q.text "," }) {|member|
|
q.seplist(PP.mcall(self, Struct, :members), lambda { q.text "," }) {|member|
|
||||||
q.breakable
|
q.breakable
|
||||||
q.text member.to_s
|
q.text member.to_s
|
||||||
q.text '='
|
q.text '='
|
||||||
|
@ -357,7 +363,7 @@ class Struct
|
||||||
end
|
end
|
||||||
|
|
||||||
def pretty_print_cycle(q)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -496,6 +502,12 @@ if __FILE__ == $0
|
||||||
def test_list0123_11
|
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
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
class HasInspect
|
class HasInspect
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue