Skip to content

Instantly share code, notes, and snippets.

@xxx
Created November 9, 2009 20:38
Show Gist options
  • Save xxx/230263 to your computer and use it in GitHub Desktop.
Save xxx/230263 to your computer and use it in GitHub Desktop.
# Giles Bowkett, Greg Brown, and several audience members from Giles' Ruby East presentation.
# hacked a touch by mpd to work with modern distributions.
require 'tempfile'
class InteractiveEditor
attr_accessor :editor
def initialize(editor = :vim)
@editor = editor.to_s
if @editor == "mate"
@editor = "mate -w"
end
end
def edit
@file ||= Tempfile.new("irb_tempfile")
system("#{@editor} #{@file.path}")
execute
end
def execute
@file.open
@file.rewind
Object.class_eval(@file.read)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment