Method: Pathname#append_lines

Defined in:
lib/pleasant_path/pathname.rb

#append_lines(lines, eol: $/) ⇒ self

Appends each object in lines as a string plus eol (end-of-line) characters to the file indicated by the Pathname. Creates the file if it does not exist, including any necessary parent directories. Returns the Pathname.

Examples:

File.exist?("path/to/file")  # false

Pathname.new("path/to/file").append_lines([:one, :two]).append_lines([:three, :four])
  # == Pathname.new("path/to/file")

File.read("path/to/file")    # == "one\ntwo\nthree\nfour\n"

Parameters:

Returns:

  • (self)


1008
1009
1010
1011
# File 'lib/pleasant_path/pathname.rb', line 1008

def append_lines(lines, eol: $/)
  self.make_dirname.open("a"){|f| f.write_lines(lines, eol: eol) }
  self
end