FakeFS module
SEPARATOR_LIST | = | "#{Regexp.quote File::ALT_SEPARATOR}" \ "#{Regexp.quote File::SEPARATOR}".freeze |
SEPARATOR_PAT | = | /[#{SEPARATOR_LIST}]/ |
SEPARATOR_LIST | = | "#{Regexp.quote File::SEPARATOR}".freeze |
SEPARATOR_PAT | = | /#{Regexp.quote File::SEPARATOR}/ |
Create a Pathname object from the given String (or String-like object). If path contains a NUL character (\0), an ArgumentError is raised.
Compare this pathname with other. The comparison is string-based. Be aware that two different paths (foo.txt and ./foo.txt) can refer to the same file.
Predicate method for testing whether a path is absolute. It returns true if the pathname begins with a slash.
Iterates over and yields a new Pathname object for each element in the given path in ascending order.
Pathname.new('/path/to/some/file.rb').ascend { |v| p v} #<Pathname:/path/to/some/file.rb> #<Pathname:/path/to/some> #<Pathname:/path/to> #<Pathname:/path> #<Pathname:/> Pathname.new('path/to/some/file.rb').ascend { |v| p v} #<Pathname:path/to/some/file.rb> #<Pathname:path/to/some> #<Pathname:path/to> #<Pathname:path>
It doesn‘t access actual filesystem.
This method is available since 1.8.5.
Returns the children of the directory (files and subdirectories, not recursive) as an array of Pathname objects. By default, the returned pathnames will have enough information to access the files. If you set with_directory to false, then the returned pathnames will contain the filename only.
For example:
pn = Pathname("/usr/lib/ruby/1.8") pn.children # -> [ Pathname:/usr/lib/ruby/1.8/English.rb, Pathname:/usr/lib/ruby/1.8/Env.rb, Pathname:/usr/lib/ruby/1.8/abbrev.rb, ... ] pn.children(false) # -> [ Pathname:English.rb, Pathname:Env.rb, Pathname:abbrev.rb, ... ]
Note that the result never contain the entries . and .. in the directory because they are not children.
This method has existed since 1.8.1.
Returns clean pathname of self with consecutive slashes and useless dots removed. The filesystem is not accessed.
If consider_symlink is true, then a more conservative algorithm is used to avoid breaking symbolic linkages. This may retain more .. entries than absolutely necessary, but without accessing the filesystem, this can‘t be avoided. See realpath.
Clean the path simply by resolving and removing excess "." and ".." entries. Nothing more, nothing less.
Iterates over and yields a new Pathname object for each element in the given path in descending order.
Pathname.new('/path/to/some/file.rb').descend { |v| p v} #<Pathname:/> #<Pathname:/path> #<Pathname:/path/to> #<Pathname:/path/to/some> #<Pathname:/path/to/some/file.rb> Pathname.new('path/to/some/file.rb').descend { |v| p v} #<Pathname:path> #<Pathname:path/to> #<Pathname:path/to/some> #<Pathname:path/to/some/file.rb>
It doesn‘t access actual filesystem.
This method is available since 1.8.5.
Iterates over the children of the directory (files and subdirectories, not recursive). It yields Pathname object for each child. By default, the yielded pathnames will have enough information to access the files. If you set with_directory to false, then the returned pathnames will contain the filename only.
Pathname("/usr/local").each_child { |f| p f } #=> #<Pathname:/usr/local/share> # #<Pathname:/usr/local/bin> # #<Pathname:/usr/local/games> # #<Pathname:/usr/local/lib> # #<Pathname:/usr/local/include> # #<Pathname:/usr/local/sbin> # #<Pathname:/usr/local/src> # #<Pathname:/usr/local/man> Pathname("/usr/local").each_child(false) { |f| p f } #=> #<Pathname:share> # #<Pathname:bin> # #<Pathname:games> # #<Pathname:lib> # #<Pathname:include> # #<Pathname:sbin> # #<Pathname:src> # #<Pathname:man>
Iterates over each component of the path.
Pathname.new("/usr/bin/ruby").each_filename { |filename| ... } # yields "usr", "bin", and "ruby".
Pathname#join joins pathnames.
path0.join(path1, …, pathN) is the same as path0 + path1 + … + pathN.
Returns the real (absolute) pathname of self in the actual filesystem. The real pathname doesn‘t contain symlinks or useless dots.
The last component of the real pathname can be nonexistent.
Returns the real (absolute) pathname of self in the actual filesystem not containing symlinks or useless dots.
All components of the pathname must exist when this method is called.
relative_path_from returns a relative path from the argument to the receiver. If self is absolute, the argument must be absolute too. If self is relative, the argument must be relative too.
relative_path_from doesn‘t access the filesystem. It assumes no symlinks.
ArgumentError is raised when it cannot find a relative path.
This method has existed since 1.8.1.
root? is a predicate for root directories. I.e. it returns true if the pathname consists of consecutive slashes.
It doesn‘t access actual filesystem. So it may return false for some pathnames which points to roots such as /usr/...