Search code examples
rubycommand-lineterminalirb

Command line / IRB won't return values - Ruby


When I use irb in the command line for ruby, sometimes it won't return any values. This seems to be happening after I've made a typo or entered incorrect code.

How do I exit this mode and go back to using irb normally? It won't let me quit with the 'quit' command, and I have to shut down the command line / Terminal and go back into it.

When this happens in vim you can press esc ! q n enter in sequence and it brings you back into the editor.

I've attached a screen shot showing what happens - as you can see it won't return any value for i in this instance.

Thanks enter image description here


Solution

  • This occurs when you have entered an incomplete expression that requires closing characters of some kind to complete it. Example:

    Incomplete expression in IRB

    The ? in the prompt indicates that the REPL is waiting on closing characters to evaluate the expression.

    You can exit this state by completing the expression or by aborting its evaluation with Ctrl+c.