summaryrefslogtreecommitdiff
path: root/lib/pp.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-27 04:08:31 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-27 04:08:31 +0000
commit4319c0235d129e9a535432703e38a032fcf33e8f (patch)
treee935dbbca9a45c40589b27967a39772adb7b10ab /lib/pp.rb
parent37c552e550f5fa51435f7f6f1efcd4d3479b5df4 (diff)
* lib/pp.rb (PP:ObjectMixin#pretty_print): delegates has no inspect
method. [ruby-core:25804] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pp.rb')
-rw-r--r--lib/pp.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/pp.rb b/lib/pp.rb
index a71ce9db38..2804ecd117 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -283,9 +283,23 @@ 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\)#/ !~ Object.instance_method(:method).bind(self).call(:inspect).inspect
+ method_method = Object.instance_method(:method).bind(self)
+ begin
+ inspect_method = method_method.call(:inspect)
+ rescue NameError
+ end
+ begin
+ to_s_method = method_method.call(:to_s)
+ rescue NameError
+ end
+ if inspect_method && /\(Kernel\)#/ !~ inspect_method.inspect
+ q.text self.inspect
+ elsif !inspect_method && self.respond_to?(:inspect)
q.text self.inspect
- elsif /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:to_s).inspect && instance_variables.empty?
+ elsif to_s_method && /\(Kernel\)#/ !~ to_s_method.inspect &&
+ instance_variables.empty?
+ q.text self.to_s
+ elsif !to_s_method && self.respond_to?(:to_s)
q.text self.to_s
else
q.pp_object(self)