How to get unstuck in Ruby irb? [duplicate]
Asked Answered
V

3

5

Possible Duplicate:
Is there a way to get out of a “hung” state in IRB?

I am using IRB. When I am coding I noticed that I get "stuck" when the line ends with "/":

irb(main):057:0/

When that happens I cannot do anything, I can't exit, define things, etc. It keeps looping back to lines that end in "/".

But, when a line ends like this:

irb(main):056:0>

everything seems to work fine. I can exit if needed, define anything, etc.

How can I get unstuck when a line ends in "/"?

Voiced answered 6/11, 2012 at 23:8 Comment(1)
Good question, I usually just kill the process :x Also, congrats.Jolandajolanta
C
8

You can press ctrl + c followed by return to get back IRB's prompt.

Catch answered 6/11, 2012 at 23:11 Comment(1)
make sure to accept alex's answer.Burseraceous
L
5

When you are 'stuck' in IRB it is usually because of an unmatched closing delimiter, such as a single quote not matching a double quote.

For this specific question it is due to being in a Regexp object, of which the delimiter is a '/' that you have pressed. This is identical in action to having an open quote that you don't close. As soon as you end the forward slash to close the Regexp, you will find yourself on the next prompt, and you will see some return from IRB on the line prior to your cursor location. So, it is appropriate to simply close the delimiter.

Perhaps, and this can only be a fishing expedition, you meant to ignore the return at the end of the line instead, and when you should have used the backslash ('\') you used the forward slash?

Control-C is kind of heavy handed, as it attempts to send an interrupt. Control-D is the EOD or End of Data* character, and so will generally let IRB know that you are done inputting data on the line (or stream).

This works for more than simply IRB and can get you out of some pretty tough places, without terminating the application that is running. Allowing you to have a graceful exit, or even continue running the program, and correcting your mistake, such as happens sometimes in IRB.

Screenshot of situation where missing one of the parenthesis are missing.

Of course, if that fails, then try control-c it will likely be just heavy handed enough to get you through.


*: historically, EOT or "End of Tape" or "End of Transmission". It may be simply my mnemonic to relate it to 'data' as in a stream of input.

Larena answered 7/11, 2012 at 0:20 Comment(0)
B
2

That's caused by hitting Enter when the line ends in an unterminated regex. You can either use Ctrl+C like alex said, or complete the regexp by ending it with another slash (or, if you began the regexp with %{, end it with a }, etc.)

Bonnibelle answered 7/11, 2012 at 0:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.