How do you save IRB inputs to a .rb file?
Asked Answered
D

4

14

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!

Dagoba answered 19/11, 2010 at 21:34 Comment(1)
Related to: #4219440Untrue
F
32

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
Faintheart answered 19/11, 2010 at 21:51 Comment(0)
R
2

You can run vim in irb:

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

Rune answered 19/11, 2010 at 21:43 Comment(0)
R
0

Take a look at watir-console.

Raylenerayless answered 22/11, 2010 at 10:52 Comment(0)
T
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

Teresaterese answered 29/4, 2013 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.