Reset IRB Console
Asked Answered
K

3

12

How does one go about saying goodbye to all constants, objects, and the like defined in an irb session to return to a clean slate? By "in", I mean without manipulating subsessions.

Krafftebing answered 22/4, 2012 at 20:7 Comment(1)
Quit and restart? irb isn't exactly heavy weight enough to worry about restarting it.Jewell
W
41

Type

exec($0)

in your irb console session.

Woodnote answered 22/4, 2012 at 20:29 Comment(5)
+1 LOL, awesome answer. And save a character and your shift key with exec $0Physician
exec __FILE__ would be better since it reload any scripts pulled in with IRB too: give exec $0 in rails console, and you'll see what I mean. However, these commands don't maintain any options that were passed when executing irb (e.g. irb --prompt simple), and they'll both fail in a subsession.Krafftebing
Pretty clever. Of course I'm not sure if this is faster than CTRL+D, ↑, enter.Raconteur
Perhaps this might be of some help to you? #4749976 Making a custom irb might be the only way to do it.Woodnote
Customization did work; a custom IRB altogether would have been overkill. I ended up adding a function to irbrc that creates/destroys isolated namespaces wherein I can play.Krafftebing
T
3

i am using fedora 16, exec $0 do not work for me. but i found the the way below:

CTRL+L or system("clear") or system("reset")

Tramontane answered 3/6, 2012 at 0:54 Comment(1)
system("command") actually executes the command in a subshell. The man pages tell us that clear will simply "clear the terminal screen". While reset comes with a few more bells and whistles, it still yields only a superficial change. Anything instantiated in the IRB session still lives on in memory. Sunny J's suggestion cleverly executes the command used to jump into IRB in the first place. I'm a bit puzzled, however, why you had trouble. What output do you see on puts $0?Krafftebing
F
0

On Windows (CMD): system("cls")

Folkway answered 26/4, 2024 at 7:27 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.