diff options
Diffstat (limited to 'lib/pp.rb')
-rw-r--r-- | lib/pp.rb | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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) |