Class: InteractiveEditor

Inherits:
Object show all
Defined in:
lib/interactive_editor.rb

Overview

Giles Bowkett, Greg Brown, and several audience members from Giles’ Ruby East presentation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(editor = :vim) ⇒ InteractiveEditor

Returns a new instance of InteractiveEditor.



4
5
6
7
8
9
# File 'lib/interactive_editor.rb', line 4

def initialize(editor = :vim)
  @editor = editor.to_s
  if @editor == "mate"
    @editor = "mate -w"
  end
end

Instance Attribute Details

#editorObject

Returns the value of attribute editor.



3
4
5
# File 'lib/interactive_editor.rb', line 3

def editor
  @editor
end

Instance Method Details

#editObject



10
11
12
13
14
15
16
17
18
# File 'lib/interactive_editor.rb', line 10

def edit
  unless @file
    @file = Tempfile.new("irb_tempfile")
  end
  system("#{@editor} #{@file.path}")
  Object.class_eval(`cat #{@file.path}`)
  rescue Exception => error
    puts error
end