Class IO
In: lib/extensions/io.rb
Parent: Object

This is Ruby‘s built-in IO class.

Methods

write   writelines  

Public Class methods

Writes the given data to the given path and closes the file. This is done in binary mode, complementing IO.read in standard Ruby.

Returns the number of bytes written.

[Source]

# File lib/extensions/io.rb, line 26
    def write(path, data)
      File.open(path, "wb") do |file|
        return file.write(data)
      end
    end

Writes the given array of data to the given path and closes the file. This is done in binary mode, complementing IO.readlines in standard Ruby.

Note that readlines (the standard Ruby method) returns an array of lines with newlines intact, whereas writelines uses puts, and so appends newlines if necessary. In this small way, readlines and writelines are not exact opposites.

Returns nil.

[Source]

# File lib/extensions/io.rb, line 51
    def writelines(path, data)
      File.open(path, "wb") do |file|
        file.puts(data)
      end
    end

[Validate]