From ed3264d37abc54e3aade229751a9165ffd37ca2e Mon Sep 17 00:00:00 2001 From: Nobuhiro IMAI Date: Thu, 7 Jan 2021 19:21:06 +0900 Subject: [ruby/irb] refactoring an error handling in `IRB::Inspector` * moved rescue clause to `#inspect_value` to catch all failures in inspectors * test with all (currently five kind of) inspect modes - tweaked the input due to only `Marshal` can inspect(dump) a `BasicObject` https://github.com/ruby/irb/commit/9d112fab8e --- lib/irb/inspector.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/irb/inspector.rb b/lib/irb/inspector.rb index 66837f1390..92de2830bc 100644 --- a/lib/irb/inspector.rb +++ b/lib/irb/inspector.rb @@ -100,21 +100,19 @@ module IRB # :nodoc: # Proc to call when the input is evaluated and output in irb. def inspect_value(v) @inspect.call(v) + rescue + puts "(Object doesn't support #inspect)" + '' end end Inspector.def_inspector([false, :to_s, :raw]){|v| v.to_s} Inspector.def_inspector([:p, :inspect]){|v| - begin - result = v.inspect - if IRB.conf[:MAIN_CONTEXT]&.use_colorize? && Color.inspect_colorable?(v) - result = Color.colorize_code(result) - end - result - rescue NoMethodError - puts "(Object doesn't support #inspect)" - '' + result = v.inspect + if IRB.conf[:MAIN_CONTEXT]&.use_colorize? && Color.inspect_colorable?(v) + result = Color.colorize_code(result) end + result } Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require "irb/color_printer"}){|v| if IRB.conf[:MAIN_CONTEXT]&.use_colorize? -- cgit v1.2.3