Method: String#write_to_file

Defined in:
lib/pleasant_path/string.rb

#write_to_file(file) ⇒ self

Writes the String to the specified file, overwriting the file if it exists. Creates the file if it does not exist, including any necessary parent directories. Returns the String.

Examples:

"hello world".write_to_file("out.txt")  # == "hello world"
File.read("out.txt")                    # == "hello world"

Parameters:

Returns:

  • (self)

See Also:



42
43
44
45
# File 'lib/pleasant_path/string.rb', line 42

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