Sha256: 6924f2e0c5991a237541570a8436e837366f5733b0ec5db1aae88b13a48d0b2c

Contents?: true

Size: 605 Bytes

Versions: 1

Compression:

Stored size: 605 Bytes

Contents

require 'tempfile'

module OpenStringInEditor
  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

  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
end

class String
  include OpenStringInEditor
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
string_to_editor-0.0.3 lib/string_to_editor.rb