Rails: How to cancel current statements in rails console?

不打扰是莪最后的温柔 提交于 2019-12-21 15:41:04

问题


I'm using Rails 2.3.8 with jRuby for a project. and I regularly use rails console for testing my classes and API, where somehow I experience one problem. when I am working in the Rails console, if I mistakenly input some multi-line commands, is there a way to cancel it somewhere in the middle?

e.g.:

>> [1,2,3,4].inject(1){
?>

All I found is it will be expecting me to finish the whole completed statement, but all I wanna do is to cancel all current statements.

I've tried Ctrl+C, but it didn't work for me.

Any advice would be very much appreciated.


回答1:


At the prompt, you can use the following command to control the irb session.

conf.ignore_sigint= true/false

This specifies the behavior of ^C (control-c). If false, ^C will quit irb. If true, ^C during input will cancel input and return to the top level; during execution, ^C will abort the current operation.

On the underside, rails console uses IRB. Also see:

http://www.rubycentral.com/pickaxe/irb.html

Edit

rubycentral.com link is dead.



来源:https://stackoverflow.com/questions/11026598/rails-how-to-cancel-current-statements-in-rails-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!