diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-07 10:02:58 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-07 10:02:58 +0000 |
| commit | 4fa29960268b391eb1d0887258aafc818ffd2750 (patch) | |
| tree | 10b89f4ab9ba5d92add48fbb4f145fe14f569223 /lib | |
| parent | 6d34bf2b506d5c81f529a828857b9322608d28c6 (diff) | |
| download | ruby-4fa29960268b391eb1d0887258aafc818ffd2750.tar.gz ruby-4fa29960268b391eb1d0887258aafc818ffd2750.tar.xz ruby-4fa29960268b391eb1d0887258aafc818ffd2750.zip | |
* lib/pp.rb: call original "method" method instead of redefined one.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pp.rb | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -283,9 +283,9 @@ class PP < PrettyPrint # This module provides predefined #pretty_print methods for some of # the most commonly used built-in classes for convenience. def pretty_print(q) - if /\(Kernel\)#/ !~ method(:inspect).inspect + if /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:inspect).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 else q.pp_object(self) @@ -317,7 +317,7 @@ class PP < PrettyPrint # However, doing this requires that every class that #inspect is called on # implement #pretty_print, or a RuntimeError will be raised. 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}" end PP.singleline_pp(self, '') @@ -516,6 +516,13 @@ if __FILE__ == $0 a = OverriddenStruct.new(1,2) assert_equal("#<struct Struct::OverriddenStruct members=1, class=2>\n", PP.pp(a, '')) end + + def test_redefined_method + o = "" + def o.method + end + assert_equal(%(""\n), PP.pp(o, "")) + end end class HasInspect |
