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.
Asked
Active
Viewed 8,170 times
12

fny
- 31,255
- 16
- 96
- 127
-
4Quit and restart? `irb` isn't exactly heavy weight enough to worry about restarting it. – mu is too short Apr 22 '12 at 20:47
2 Answers
39
Type
exec($0)
in your irb console session.

Andrew Marshall
- 95,083
- 20
- 220
- 214

sunnyrjuneja
- 6,033
- 2
- 32
- 51
-
3+1 LOL, awesome answer. And save a character and your shift key with `exec $0` – DigitalRoss Apr 22 '12 at 21:27
-
1`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. – fny Apr 22 '12 at 21:30
-
2Pretty clever. Of course I'm not sure if this is faster than CTRL+D, ↑, enter. – Andrew Marshall Apr 22 '12 at 22:12
-
Perhaps this might be of some help to you? http://stackoverflow.com/questions/4749476/how-can-i-pass-arguments-to-irb-if-i-dont-specify-programfile Making a custom irb might be the only way to do it. – sunnyrjuneja Apr 22 '12 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. – fny Apr 23 '12 at 22:54
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")

lzj509649444
- 95
- 1
- 7
-
`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`? – fny Jun 03 '12 at 02:56