For what it's worth I have been using interactive_editor gem in irb for a
bit now. It allows me to open nvi or vim within irb and also supports other
cli editors( emacs, pico/nano, and even ed for those still <3 the original
unix line editor)

Though it is the reverse of setting up your editor to execute the script
from within the editor it has been quite a pleasant experience with adhoc
irb sessions.

Features are simplified. For example from within irb I type vim and then a
temp file is created which treats it as a *.rb file and allows syntax color
highlighting.

After write out the temp file the buffer is pushed back into the irb
interpreter and ready to use.

If I need to refactor my code further I can reopen the temp file again and
edit. If I'm done and happy with my creation I can save it as a named file.
If I am not content when I leave irb it will simply be flushed.

Of course you can open named files from within irb and within your text
editor running on top of irb as well.

Anyone who prefers these type of editors and has not discovered
interactive_editor may want to investigate this gem. I use it daily and I am
content as it fills the gap of experimentation much the same as posix
programming an almquist shell script directly in the terminal command line.

Now if there was a gem to manipulate irb's <TAB> completion system to act
just like zsh's innovative completion system it would be one hell of a
development environment.