How to escape/exit in IRB after entering code that requires more input/does not execute right away [closed]
Asked Answered
A

1

6

A particular line of code results in no output, and IRB exits out of the >> prompt. I am not looking to exit IRB, but just to exit to a state preceding the line of code that caused the >> prompt to go away.

>> stop_words = %w {the a and if}
>> stop_words.each{|x| stop_words << x.capitalize}
quit
quit
quit
  1. Once I enter this situation, I cannot even exit the IRB shell, as the 'quit' command does not execute any changes.
  2. I would like to exit the state and still have my preceding variable definitions intact, so that in the code example, I could call on stop_words to experiment with it. Any elucidation/insight into what's going on here is appreciated.
Antoninus answered 30/1, 2013 at 4:38 Comment(10)
I had to add quotation marks to the >> so that stackoverflow could display them. It's not a pretty edit job but it gives a rough idea of what I'm trying to communicate.Antoninus
No, you don’t have to add "s. Instead properly format code blocks.Astri
@sawa That last quote may have not been added for formatting purposes, as the OP only stated they had to quote the >>s.Astri
@AndrewMarshall But it is not balanced. You might have better idea how it is supposed to be. Please edit if you have an idea. I am not sure.Salvadorsalvadore
@Salvadorsalvadore So? It could very well be the cause of the OP’s problem.Astri
@AndrewMarshall Maybe you are right. I added the quotation.Salvadorsalvadore
I don't think the quotation was intended. The problem occurs without it.Pussy
By the way, I assume you realize it hangs because it's an infinite loop right?Pussy
Geoff is correct in saying the problem occurs without it and in his inference that the quotation was not intended. I accidentally added it while trying to format the question as quickly as possible. Also, Thank you Andrew Marshall for the link to properly formatting code blocks.Antoninus
@Geoff. After printing the contents of stop_words I realized that was the case, but was not familiar enough with the logic and how the methods work to realize it by assessing the code alone. I'm working on it.Antoninus
A
3

Your code infinitely loops, so you don’t get a new prompt as it is still processing your previous command.

You can hit CtrlC to abort the currently running command immediately.

Astri answered 30/1, 2013 at 4:53 Comment(6)
I assumed this too, but for some reason it doesn't always work.Pussy
@Pussy I assume you mean the Ctrl-C? Can you give an example? Also it isn’t really the “line”, but the larger statement, as it will get you out of blocks and things. Not sure what the best term for that is.Astri
Control-C worked to solve the issue.Antoninus
Also, the extraneous quote was a typo as I was struggling to haphazardly format my question. It wasn't a part of my original code.Antoninus
It doesn't always work for me. Here's my output: pastebin.com/CkZHvcA7Pussy
@Pussy weird. I rarely use IRB anymore because of weird edge case issues like this. I now exclusively use Pry.Astri

© 2022 - 2024 — McMap. All rights reserved.