* lib/pp.rb: call original "method" method instead of redefined one.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d7d85f9ecd
commit
6f9ded1fb0
@ -1,3 +1,7 @@
|
|||||||
|
Thu Jun 7 19:02:48 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* lib/pp.rb: call original "method" method instead of redefined one.
|
||||||
|
|
||||||
Thu Jun 7 17:20:57 2007 Koichi Sasada <ko1@atdot.net>
|
Thu Jun 7 17:20:57 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* iseq.c (prepare_iseq_build): freeze filename and name string.
|
* iseq.c (prepare_iseq_build): freeze filename and name string.
|
||||||
|
13
lib/pp.rb
13
lib/pp.rb
@ -283,9 +283,9 @@ class PP < PrettyPrint
|
|||||||
# This module provides predefined #pretty_print methods for some of
|
# This module provides predefined #pretty_print methods for some of
|
||||||
# the most commonly used built-in classes for convenience.
|
# the most commonly used built-in classes for convenience.
|
||||||
def pretty_print(q)
|
def pretty_print(q)
|
||||||
if /\(Kernel\)#/ !~ method(:inspect).inspect
|
if /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:inspect).inspect
|
||||||
q.text self.inspect
|
q.text self.inspect
|
||||||
elsif /\(Kernel\)#/ !~ method(:to_s).inspect && instance_variables.empty?
|
elsif /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:to_s).inspect && instance_variables.empty?
|
||||||
q.text self.to_s
|
q.text self.to_s
|
||||||
else
|
else
|
||||||
q.pp_object(self)
|
q.pp_object(self)
|
||||||
@ -317,7 +317,7 @@ class PP < PrettyPrint
|
|||||||
# However, doing this requires that every class that #inspect is called on
|
# However, doing this requires that every class that #inspect is called on
|
||||||
# implement #pretty_print, or a RuntimeError will be raised.
|
# implement #pretty_print, or a RuntimeError will be raised.
|
||||||
def pretty_print_inspect
|
def pretty_print_inspect
|
||||||
if /\(PP::ObjectMixin\)#/ =~ method(:pretty_print).inspect
|
if /\(PP::ObjectMixin\)#/ =~ Object.instance_method(:method).bind(self).call(:pretty_print).inspect
|
||||||
raise "pretty_print is not overridden for #{self.class}"
|
raise "pretty_print is not overridden for #{self.class}"
|
||||||
end
|
end
|
||||||
PP.singleline_pp(self, '')
|
PP.singleline_pp(self, '')
|
||||||
@ -516,6 +516,13 @@ if __FILE__ == $0
|
|||||||
a = OverriddenStruct.new(1,2)
|
a = OverriddenStruct.new(1,2)
|
||||||
assert_equal("#<struct Struct::OverriddenStruct members=1, class=2>\n", PP.pp(a, ''))
|
assert_equal("#<struct Struct::OverriddenStruct members=1, class=2>\n", PP.pp(a, ''))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_redefined_method
|
||||||
|
o = ""
|
||||||
|
def o.method
|
||||||
|
end
|
||||||
|
assert_equal(%(""\n), PP.pp(o, ""))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class HasInspect
|
class HasInspect
|
||||||
|
Loading…
x
Reference in New Issue
Block a user