寻找在Ruby on Rails的IRB中退出已加载脚本的最佳方法。Kernel.exit和Kernel.abort会完全弹出IRB会话。理想情况下,这应该在某些条件下发生。
我的脚本/my_script.rb:
puts "My Script is running!"
# if some criteria, stop execution of this script without stoping IRB
puts "This will never happen"
理想的结果:
$ rails console
irb(main):001:0> load 'script/my_script.rb'
My Script is running!
irb(main):002:0>