Module: OpenStringInEditor

Included in:
String
Defined in:
lib/string_to_editor.rb

Instance Method Summary collapse

Instance Method Details

#viewObject



12
13
14
15
16
17
18
19
# File 'lib/string_to_editor.rb', line 12

def view
  if ENV['EDITOR']
    write_to_tmp_file
    system("#{ENV['EDITOR']} #{@path_of_tmp_file_for_string_to_editor} &")
  else
    raise ":view was called for a String, but the EDITOR variable was not set in ENV"
  end
end

#write_to_tmp_fileObject



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

def write_to_tmp_file
  return @path_of_tmp_file_for_string_to_editor if @path_of_tmp_file_for_string_to_editor
  Tempfile.open('ruby_string') do |tempfile|
    tempfile.puts self
    @path_of_tmp_file_for_string_to_editor = tempfile.path
  end
end