Method: Pathname#write_lines

Defined in:
lib/pleasant_path/pathname.rb

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

Writes each object in lines as a string plus eol (end-of-line) characters to the file indicated by the Pathname, overwriting the file if it exists. 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").write_lines([:one, :two])
  # == Pathname.new("path/to/file")

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

Parameters:

Returns:

  • (self)


987
988
989
990
# File 'lib/pleasant_path/pathname.rb', line 987

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