Class: Array

Inherits:
Object show all
Defined in:
lib/pleasant_path/array.rb

Instance Method Summary collapse

Instance Method Details

#append_to_file(file) ⇒ Array

Appends the array as lines to the given file, and returns the array. A new line character ($/) is written after each line. The file is created if it does not exist. Any necessary parent directories are created if they do not exist.

Examples:

[:one, :two].append_to_file("out.txt")     # == [:one, :two]
File.read("out.txt")                       # == "one\ntwo\n"
[:three, :four].append_to_file("out.txt")  # == [:three, :four]
File.read("out.txt")                       # == "one\ntwo\nthree\nfour\n"

Parameters:

Returns:



32
33
34
35
# File 'lib/pleasant_path/array.rb', line 32

def append_to_file(file)
  file.to_pathname.append_lines(self)
  self
end

#write_to_file(file) ⇒ Array

Writes the array as lines to the given file, and returns the array. A new line character ($/) is written after each line. The file is overwritten if it already exists. Any necessary parent directories are created if they do not exist.

Examples:

[:one, :two].write_to_file("out.txt")  # == [:one, :two]
File.read("out.txt")                   # == "one\ntwo\n"

Parameters:

Returns:



14
15
16
17
# File 'lib/pleasant_path/array.rb', line 14

def write_to_file(file)
  file.to_pathname.write_lines(self)
  self
end