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.
2 Answers
Type
exec($0)
in your irb console session.
-
3+1 LOL, awesome answer. And save a character and your shift key with
exec $0
Apr 22, 2012 at 21:27 -
1
exec __FILE__
would be better since it reload any scripts pulled in with IRB too: giveexec $0
inrails console
, and you'll see what I mean. However, these commands don't maintain any options that were passed when executingirb
(e.g.irb --prompt simple
), and they'll both fail in a subsession.– fnyApr 22, 2012 at 21:30 -
2Pretty clever. Of course I'm not sure if this is faster than CTRL+D, ↑, enter. Apr 22, 2012 at 22:12
-
Perhaps this might be of some help to you? stackoverflow.com/questions/4749476/… Making a custom irb might be the only way to do it. Apr 22, 2012 at 22:49
-
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.– fnyApr 23, 2012 at 22:54
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 thecommand
in a subshell. The man pages tell us thatclear
will simply "clear the terminal screen". Whilereset
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 onputs $0
?– fnyJun 3, 2012 at 2:56
irb
isn't exactly heavy weight enough to worry about restarting it.