Class: String

Inherits:
Object show all
Defined in:
lib/pleasant_path/string.rb

Instance Method Summary collapse

Instance Method Details

#/(child) ⇒ Pathname

Constructs a Pathname from the String, and appends child to the Pathname.

Examples:

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

Parameters:

Returns:



26
27
28
# File 'lib/pleasant_path/string.rb', line 26

def /(child)
  self.path / child
end

#append_to_file(file) ⇒ self

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

Examples:

"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"

Parameters:

Returns:

  • (self)

See Also:



61
62
63
64
# File 'lib/pleasant_path/string.rb', line 61

def append_to_file(file)
  file.to_pathname.append_text(self)
  self
end

#to_pathnamePathname Also known as: path

Constructs a Pathname from the String.

Examples:

"path/to/file".to_pathname  # == Pathname.new("path/to/file")

Returns:



9
10
11
# File 'lib/pleasant_path/string.rb', line 9

def to_pathname
  Pathname.new(self)
end

#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