Method: Pathname#append_text

Defined in:
lib/pleasant_path/pathname.rb

#append_text(text) ⇒ self

Appends text to the file indicated by the Pathname. Creates the file if it does not exist, including any necessary parent directories. Returns the Pathname.

Examples:

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

Pathname.new("path/to/file").append_text("hello").append_text(" world")
  # == Pathname.new("path/to/file")

File.read("path/to/file")    # == "hello world"

Parameters:

Returns:

  • (self)


966
967
968
969
# File 'lib/pleasant_path/pathname.rb', line 966

def append_text(text)
  self.make_dirname.open("a"){|f| f.write(text) }
  self
end