From 9fa0d0058d234ee2d3557761605870a4904840c2 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 14 Apr 2018 13:05:52 +0000 Subject: irb.rb: restore the last error * lib/irb.rb (eval_input): restore the last error `$!`, as the previous result. [Feature #14684] * lib/irb/context.rb (evaluate): add `exception` keyword argument to set the last error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/irb/context.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/irb') diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 1a06ebfad1..b82aaea6a6 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -376,8 +376,12 @@ module IRB @debug_level > 0 end - def evaluate(line, line_no) # :nodoc: + def evaluate(line, line_no, exception: nil) # :nodoc: @line_no = line_no + if exception + line = "begin ::Kernel.raise _; rescue _.class; #{line}; end" + @workspace.local_variable_set(:_, exception) + end set_last_value(@workspace.evaluate(self, line, irb_path, line_no)) end -- cgit v1.2.3