diff options
author | Stan Lo <stan001212@gmail.com> | 2023-03-13 22:31:30 +0800 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-03-13 14:31:37 +0000 |
commit | 1095baed34dca15b9d8c6c54ea2f89bbaf67fb52 (patch) | |
tree | b3fdbae6231cdacffa7053c021edf266531aef50 /lib/irb/color_printer.rb | |
parent | 8c6b349805e2f17a57576b8dfad31e5681d6b0e9 (diff) | |
download | ruby-1095baed34dca15b9d8c6c54ea2f89bbaf67fb52.tar.gz |
[ruby/irb] Support inspecting BasicObject
(https://github.com/ruby/irb/pull/541)
https://github.com/ruby/irb/commit/1dc2a406a3
Diffstat (limited to 'lib/irb/color_printer.rb')
-rw-r--r-- | lib/irb/color_printer.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/irb/color_printer.rb b/lib/irb/color_printer.rb index 1127bcecb4..a4eeb140cd 100644 --- a/lib/irb/color_printer.rb +++ b/lib/irb/color_printer.rb @@ -4,6 +4,10 @@ require_relative 'color' module IRB class ColorPrinter < ::PP + METHOD_IS_A = Object.instance_method(:is_a?) + METHOD_RESPOND_TO = Object.instance_method(:respond_to?) + METHOD_INSPECT = Object.instance_method(:inspect) + class << self def pp(obj, out = $>, width = screen_width) q = ColorPrinter.new(out, width) @@ -22,9 +26,11 @@ module IRB end def pp(obj) - if obj.is_a?(String) + if METHOD_IS_A.bind(obj).call(String) # Avoid calling Ruby 2.4+ String#pretty_print that splits a string by "\n" text(obj.inspect) + elsif !METHOD_RESPOND_TO.bind(obj).call(:inspect) + text(METHOD_INSPECT.bind(obj).call) else super end |