class String
Public Instance Methods
/(child)
click to toggle source
append_to_file(file)
click to toggle source
Appends the String
to the specified file
. Creates the file if it does not exist, including any necessary parent directories. Returns the String
.
@see Pathname#append_text
@example
"hello".append_to_file("out.txt") # == "hello" File.read("out.txt") # == "hello" " world".append_to_file("out.txt") # == " world" File.read("out.txt") # == "hello world"
@param file [String, Pathname] @return [self]
# File lib/pleasant_path/string.rb, line 61 def append_to_file(file) file.to_pathname.append_text(self) self end
to_pathname()
click to toggle source
Constructs a Pathname
from the String
.
@example
"path/to/file".to_pathname # == Pathname.new("path/to/file")
@return [Pathname]
# File lib/pleasant_path/string.rb, line 9 def to_pathname Pathname.new(self) end
Also aliased as: path
write_to_file(file)
click to toggle source
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
.
@see Pathname#write_text
@example
"hello world".write_to_file("out.txt") # == "hello world" File.read("out.txt") # == "hello world"
@param file [String, Pathname] @return [self]
# File lib/pleasant_path/string.rb, line 42 def write_to_file(file) file.to_pathname.write_text(self) self end