Last Updated: December 14, 2016
·
480
· seawolf

Run a script before invoking IRb

I've just been writing a Ruby script for a quick demo I'm giving. Instead of writing notes, I prefer to have at hand my resultant code: I have to build it up from scratch, so it helps to keep it as simple as I can read it, and I can keep the end in sight.

The code-then-run loop quickly became tedious, especially trying to remember which bits I'd subtly changed, and trying to invoke them. Wouldn't it be more effective, I thought, if I could run my script but interactively use it, then copy my terminal output into the script when I got something working?

irb -r your_script.rb

This will tell IRb to run your script before dropping you to the prompt. I just found this great for almost seeding a script with some class definitions and stuff I don't want to type each time I reload, so that I can gradually develop on top of it.