From b315826377bfa3fae6f513da12327c9133852486 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Fri, 16 Feb 2024 16:12:50 +0000 Subject: [ruby/irb] Support repeating debugger input by passing empty input to it (https://github.com/ruby/irb/pull/856) * Test IRB's behaviour with empty input * Handle empty input and pass it to debugger Since `rdbg` accepts empty input to repeat the previous command, IRB should take empty input in `irb:rdbg` sessions and pass them to the debugger. Currently, IRB simply ignores empty input and does nothing. This commit creates `EmptyInput` to represent empty input so it can fit into the current IRB's input processing flow in `Irb#eval_input`. https://github.com/ruby/irb/commit/0e9db419be --- lib/irb.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/irb.rb') diff --git a/lib/irb.rb b/lib/irb.rb index 67e03f8bc9..fd06626e9b 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -1082,16 +1082,17 @@ module IRB loop do code = readmultiline break unless code - - if code != "\n" - yield build_statement(code), @line_no - end + yield build_statement(code), @line_no @line_no += code.count("\n") rescue RubyLex::TerminateLineInput end end def build_statement(code) + if code.match?(/\A\n*\z/) + return Statement::EmptyInput.new + end + code.force_encoding(@context.io.encoding) command_or_alias, arg = code.split(/\s/, 2) # Transform a non-identifier alias (@, $) or keywords (next, break) -- cgit v1.2.3