Created
November 9, 2009 20:38
-
-
Save xxx/230263 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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