Class: File

Inherits:
Object show all
Defined in:
lib/hash-utils/file.rb

Overview

File extension.

Since:

  • 0.11.0

Class Method Summary collapse

Class Method Details

.touch(filepath) ⇒ Object

Creates file with zero size and closes it. (In fact, touch is usually used for it.)

Parameters:

  • file (String)

    filepath path for create

Since:

  • 0.11.0



37
38
39
# File 'lib/hash-utils/file.rb', line 37

def self.touch(filepath)
    File.open(filepath, "wb").close()
end

.write(filepath, data = "") ⇒ Integer

Writes data to file and closes it in single call. Data are written in binary mode since 0.11.1.

Parameters:

  • filepath (String)

    path to file

  • data (String) (defaults to: "")

    data for write

Returns:

  • (Integer)

    length of really written data

Since:

  • 0.11.0



21
22
23
24
25
26
27
# File 'lib/hash-utils/file.rb', line 21

def self.write(filepath, data = "")
    len = nil
    File.open(filepath, "wb") do |io|
        len = io.write(data)
    end
    return len
end