13

Might sound like a newbie question (and it is since I am new to Ruby and IRB) but is there a way to save the commands you did in IRB to file? I am playing with WATIR and would love to save all my inputs to file instead of copying and pasting each.

Thanks for the help!

Enrique
  • 655
  • 1
  • 7
  • 16

4 Answers4

31

On my machine I can put this in my .irbrc file (located in your home directory):

Kernel.at_exit {
  File.open("irb.log", "w") do |f|
    f << Readline::HISTORY.to_a.join("\n")
  end
}

It creates a file irb.log that contains your readline history. Irb uses readline for command input. It might be configured not to use readline for some people, I don't know. And maybe the history will be truncated at some point, or maybe it'll be modified by certain commands you do in your irb session... but try it out and see if it works.

If you want the irb prompt and the result of each command to be included in the log, then just use tee to record the output of irb:

$ irb | tee irb.log
Paige Ruten
  • 172,675
  • 36
  • 177
  • 197
2

You can run vim in irb:

http://vimcasts.org/episodes/running-vim-within-irb/

Petrik de Heus
  • 970
  • 6
  • 9
0

I found this question when looking to do the same thing. I ended up switching from IRB to Pry; it is a separate REPL project for Ruby that has a whole host of advanced features not supported in IRB.

Well worth a look.

Pry

bigtunacan
  • 4,873
  • 8
  • 40
  • 73
0

Take a look at watir-console.

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125