Sha256: b8c4a56287c930dc33032024f7cb7d60ebb0626fe8cf1bec0d1da6864f4b68ae

Contents?: true

Size: 346 Bytes

Versions: 2

Compression:

Stored size: 346 Bytes

Contents

# -*- coding: utf-8 -*-
=begin rdoc
File#rewrite
=end

require "tempfile"

class File

  def rewrite(string)
    raise ArgumentError if !string.kind_of?(String)
    tempfile = Tempfile.new
    begin
      tempfile.write(string)
      FileUtils.mv(tempfile.path, self.path)
    ensure
      tempfile.close
      tempfile.unlink
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sixarm_ruby_file_rewrite-2.0.0 lib/sixarm_ruby_file_rewrite/file/rewrite.rb
sixarm_ruby_file_rewrite-1.0.0 lib/sixarm_ruby_file_rewrite/file/rewrite.rb