28

Basically, I'm typing along just fine in terminal, using IRB to run ruby commands:

2.0.0-p0 :014 > bank_account.withdraw(2222)
 => -1222 

But sometimes I accidentally miss out a quotation mark.

2.0.0-p0 :020 > BankAccount.create_for("Jim","Johnson)
2.0.0-p0 :021"> bank_account.withdraw(333)

If you look carefully, you'll see that the speech mark I missed out appears next to the line number on the left, next to the patch version.

From here on in, that speech mark appears everytime I run a command! And it stops the commands working:

2.0.0-p0 :021"> BankAccount.create_for("Julian","Hurley")
2.0.0-p0 :022"> BankAccount.create_for("Katt","Smith")
2.0.0-p0 :023"> exec($0)

What I want to know is, how do I get rid of that quotation mark? Or quit IRB from the command line in order to reset it?

Starkers
  • 10,273
  • 21
  • 95
  • 158

5 Answers5

42

If you haven't closed a quote, just put a quote in and hit return.

Exiting from the console can be done by typing exit, though in the circumstance your are would need to hit Control - C

muttonlamb
  • 6,341
  • 3
  • 26
  • 35
  • and if you made the mistake twice? ie did `puts 'hi` and then again `puts 'hi`. – mfaani Jan 15 '19 at 21:34
  • 1
    That will cause an error because when it his the second `'` it will close the string and then try to evaluate `hi` as a keyword – muttonlamb Jan 21 '19 at 08:28
18

Control - C followed by Control - Z. I hope it helps!

S E
  • 437
  • 4
  • 12
  • 1
    Pretty sure C-z just puts the process in the background instead of terminating it. You can type `jobs` to verify and then `fg 1` (or whatever job number) to resume the process – Josh Bodah May 29 '16 at 13:46
17

I was having the same problem. To exit irb within the terminal, type exit.

Beltalowda
  • 4,558
  • 2
  • 25
  • 33
UrbanDev
  • 183
  • 1
  • 6
7

Use Ctrl-D, it is an end-of-input for irb. If you are in the middle of some command, use Ctrl-C first to terminate the input of this command.

qknowswhat
  • 331
  • 3
  • 3
0

If you're in the middle of a multi-line block (according to the interpreter), hit Ctrl+C to break out of it.

Then you can do any of the following to quit:

  • exit (or exit())
  • quit (or quit())
  • irb_exit (or irb_exit())
  • Ctrl+D (sends the EOF character)
Roy Tinker
  • 10,044
  • 4
  • 41
  • 58