Class: String
Instance Method Summary collapse
-
#/(child) ⇒ Pathname
Joins the string and the argument with a directory separator (a la
File.join) and returns the result as aPathnameobject. -
#^(sibling) ⇒ Pathname
Treating the string as a path, joins the parent (
dirname) of the path with the argument, and returns the result as aPathnameobject. -
#append_to_file(file) ⇒ String
Appends the string to the given file, and returns the string.
-
#glob ⇒ Array<Pathname>
Treats the string as a filename pattern, and expands the pattern into matching paths as
Pathnameobjects. -
#to_pathname ⇒ Pathname
(also: #path)
Converts the string to a
Pathnameobject. -
#write_to_file(file) ⇒ String
Writes the string to the given file, and returns the string.
Instance Method Details
#/(child) ⇒ Pathname
Joins the string and the argument with a directory separator (a la File.join) and returns the result as a Pathname object.
26 27 28 |
# File 'lib/pleasant_path/string.rb', line 26 def /(child) self.path / child end |
#^(sibling) ⇒ Pathname
Treating the string as a path, joins the parent (dirname) of the path with the argument, and returns the result as a Pathname object. The mnemonic for this operator is that the resultant path goes up one directory level from the original, then goes down to the directory specified by the argument. See also Pathname#^.
41 42 43 |
# File 'lib/pleasant_path/string.rb', line 41 def ^(sibling) self.path ^ sibling end |
#append_to_file(file) ⇒ String
Appends the string to the given file, and returns the string. The file is created if it does not exist. Any necessary parent directories are created if they do not exist.
84 85 86 87 |
# File 'lib/pleasant_path/string.rb', line 84 def append_to_file(file) file.to_pathname.append_text(self) self end |
#glob ⇒ Array<Pathname>
Treats the string as a filename pattern, and expands the pattern into matching paths as Pathname objects. See also Dir.glob and Pathname.glob.
53 54 55 |
# File 'lib/pleasant_path/string.rb', line 53 def glob Pathname.glob(self) end |
#to_pathname ⇒ Pathname Also known as: path
Converts the string to a Pathname object.
9 10 11 |
# File 'lib/pleasant_path/string.rb', line 9 def to_pathname Pathname.new(self) end |
#write_to_file(file) ⇒ String
Writes the string to the given file, and returns the string. The file is overwritten if it already exists. Any necessary parent directories are created if they do not exist.
67 68 69 70 |
# File 'lib/pleasant_path/string.rb', line 67 def write_to_file(file) file.to_pathname.write_text(self) self end |