vanutsteen.nl => nerds only A blog on rails, php, computing, my bass guitar and stuff

Interactive/inline editor in irb

on in Development, Ruby

I saw the MountainWest Ruby conference video: code generation: safety scissors of metaprogramming. And the speaker (Giles Bowkett) used vi from inside irb. And I’ve never liked Vi, but using an editor from within irb is nice! Especially if you’re testing a big chunk of code.

So I began crawling the Internet for how he did this and I found the utility_belt gem. The utility belt contains the file I needed. So I installed the gem, edited my .irbrc and now I can use nano/gedit (or any other editor) from withing IRB!

These were the steps:

1
gem install utility_belt
My .irbrc:
1
2
3
4
5
6
require 'utility_belt/interactive_editor'
module InteractiveEditing
  def nano
    edit_interactively(:nano)
  end
end

Now to use nano in irb, just type: nano

And the bonus: a nice screencast that shows this feature in action. I tried to edit it with pitivi. But that really sucked. After I finally found it out how I could cut pieces I tried to save it and the whole program crashed. “apt-get remove pitivi”!

Comments