Class: CLIEditor

Inherits:
Object
  • Object
show all
Defined in:
lib/cli_editor.rb

Constant Summary collapse

BadFormatError =
Class.new StandardError

Instance Method Summary collapse

Constructor Details

#initialize(cmd = 'vim') ⇒ CLIEditor

Returns a new instance of CLIEditor.



6
7
8
# File 'lib/cli_editor.rb', line 6

def initialize(cmd = 'vim')
  @cmd = cmd
end

Instance Method Details

#edit(str) ⇒ Object



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

def edit(str)
  tf = Tempfile.new
  tf.write str
  tf.close
  system @cmd, tf.path
  tf.open
  data = tf.read
  tf.close
  tf.unlink
  data
end