diff options
Diffstat (limited to 'lib/irb.rb')
-rw-r--r-- | lib/irb.rb | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/irb.rb b/lib/irb.rb index f3abed8200..ad6ec78aa4 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -886,7 +886,11 @@ module IRB # Quits irb def IRB.irb_exit(*) - throw :IRB_EXIT + throw :IRB_EXIT, false + end + + def IRB.irb_exit!(*) + throw :IRB_EXIT, true end # Aborts then interrupts irb. @@ -968,7 +972,8 @@ module IRB conf[:IRB_RC].call(context) if conf[:IRB_RC] conf[:MAIN_CONTEXT] = context - save_history = !in_nested_session && conf[:SAVE_HISTORY] && context.io.support_history_saving? + supports_history_saving = conf[:SAVE_HISTORY] && context.io.support_history_saving? + save_history = !in_nested_session && supports_history_saving if save_history context.io.load_history @@ -979,13 +984,21 @@ module IRB end begin - catch(:IRB_EXIT) do + forced_exit = false + + forced_exit = catch(:IRB_EXIT) do eval_input end ensure trap("SIGINT", prev_trap) conf[:AT_EXIT].each{|hook| hook.call} - context.io.save_history if save_history + + if forced_exit + context.io.save_history if supports_history_saving + Kernel.exit(0) + else + context.io.save_history if save_history + end end end |