From 148518baa06c50669de98d078f743a594ffe2fba Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 27 Apr 2024 01:52:08 +0800 Subject: [ruby/irb] Suppress command return values (https://github.com/ruby/irb/pull/934) Since commands can't be chained with methods, their return values are not intended to be used. But if IRB keeps storing command return values as the last value, and print them, users may rely on such implicit behaviour. So to avoid such confusion, this commit suppresses command's return values. It also updates some commands that currently rely on this implicit behaviour. https://github.com/ruby/irb/commit/fa96bea76f --- lib/irb/context.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/irb/context.rb') diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 836b8d2625..22e855f1ef 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -587,18 +587,19 @@ module IRB def evaluate(statement, line_no) # :nodoc: @line_no = line_no - result = nil case statement when Statement::EmptyInput return when Statement::Expression result = evaluate_expression(statement.code, line_no) + set_last_value(result) when Statement::Command - result = statement.command_class.execute(self, statement.arg) + statement.command_class.execute(self, statement.arg) + set_last_value(nil) end - set_last_value(result) + nil end def evaluate_expression(code, line_no) # :nodoc: -- cgit v1.2.3