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

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

Note:

Since Ruby 1.9.3 replaced by STL native version.

Writes binary data to file and closes it in single call.

Parameters:

  • filepath (String)

    path to file

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

    data for write

Returns:

  • (Integer)

    length of really written data

Since:

  • 0.19.0



58
59
60
61
62
63
64
# File 'lib/hash-utils/file.rb', line 58

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

.touch(filepath) ⇒ Object

Since:

  • 0.11.0



78
79
80
# File 'lib/hash-utils/file.rb', line 78

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

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

Note:

Data were written in binary mode since 0.11.1, but since 0.19.0, they are written non-binary again. Binary writing is implemented via binwrite.

Note:

Since Ruby 1.9.3 replaced by STL native version.

Writes data to file and closes it in single call.

Parameters:

  • filepath (String)

    path to file

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

    data for write

Returns:

  • (Integer)

    length of really written data

Since:

  • 0.11.0



32
33
34
35
36
37
38
# File 'lib/hash-utils/file.rb', line 32

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