diff --git a/lib/irb.rb b/lib/irb.rb index fd0bfe35c..6d9c96c8f 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -612,10 +612,10 @@ def format_prompt(format, ltype, indent, line_no) # :nodoc: when "N" @context.irb_name when "m" - main_str = @context.safe_method_call_on_main(:to_s) rescue "!#{$!.class}" + main_str = "#{@context.safe_method_call_on_main(:to_s)}" rescue "!#{$!.class}" truncate_prompt_main(main_str) when "M" - main_str = @context.safe_method_call_on_main(:inspect) rescue "!#{$!.class}" + main_str = "#{@context.safe_method_call_on_main(:inspect)}" rescue "!#{$!.class}" truncate_prompt_main(main_str) when "l" ltype diff --git a/test/irb/test_debugger_integration.rb b/test/irb/test_debugger_integration.rb index 45ffb2a52..e125dbf85 100644 --- a/test/irb/test_debugger_integration.rb +++ b/test/irb/test_debugger_integration.rb @@ -51,6 +51,31 @@ def test_debug assert_match(/=> 2\| puts "hello"/, output) end + def test_debug_class_to_s_return_nil + write_ruby <<~'ruby' + class ToSReturnsNil + def to_s + nil + end + + def do_something + binding.irb + end + end + + ToSReturnsNil.new.do_something + ruby + + output = run_ruby_file do + type "debug" + type "next" + type "continue" + end + + assert_match(/irb\(\):001> debug/, output) + assert_match(/irb:rdbg\(\):002> next/, output) + end + def test_debug_command_only_runs_once write_ruby <<~'ruby' binding.irb