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.
Reset IRB Console
Type
exec($0)
in your irb console session.
+1 LOL, awesome answer. And save a character and your shift key with
exec $0
–
Physician 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 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")
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 © 2022 - 2025 — McMap. All rights reserved.
irb
isn't exactly heavy weight enough to worry about restarting it. – Jewell