class Pathname
pathname.rb
Object-Oriented Pathname Class
- Author
-
Tanaka Akira akr@m17n.org
- Documentation
-
Author and Gavin Sinclair
For documentation, see class Pathname.
Pathname represents the name of a file or directory on the filesystem, but not the file itself.
The pathname depends on the Operating System: Unix, Windows, etc. This library works with pathnames of local OS, however non-Unix pathnames are supported experimentally.
A Pathname can be relative or absolute. It’s not until you try to reference the file that it even matters whether the file exists or not.
Pathname is immutable. It has no method for destructive update.
The goal of this class is to manipulate file path information in a neater way than standard Ruby provides. The examples below demonstrate the difference.
All functionality from File, FileTest, and some from Dir and FileUtils is included, in an unsurprising way. It is essentially a facade for all of these, and more.
Examples
Example 1: Using Pathname
require 'pathname' pn = Pathname.new("/usr/bin/ruby") size = pn.size # 27662 isdir = pn.directory? # false dir = pn.dirname # Pathname:/usr/bin base = pn.basename # Pathname:ruby dir, base = pn.split # [Pathname:/usr/bin, Pathname:ruby] data = pn.read pn.open { |f| _ } pn.each_line { |line| _ }
Example 2: Using standard Ruby
pn = "/usr/bin/ruby" size = File.size(pn) # 27662 isdir = File.directory?(pn) # false dir = File.dirname(pn) # "/usr/bin" base = File.basename(pn) # "ruby" dir, base = File.split(pn) # ["/usr/bin", "ruby"] data = File.read(pn) File.open(pn) { |f| _ } File.foreach(pn) { |line| _ }
Example 3: Special features
p1 = Pathname.new("/usr/lib") # Pathname:/usr/lib p2 = p1 + "ruby/1.8" # Pathname:/usr/lib/ruby/1.8 p3 = p1.parent # Pathname:/usr p4 = p2.relative_path_from(p3) # Pathname:lib/ruby/1.8 pwd = Pathname.pwd # Pathname:/home/gavin pwd.absolute? # true p5 = Pathname.new "." # Pathname:. p5 = p5 + "music/../articles" # Pathname:music/../articles p5.cleanpath # Pathname:articles p5.realpath # Pathname:/home/gavin/articles p5.children # [Pathname:/home/gavin/articles/linux, ...]
Breakdown of functionality
Core methods
These methods are effectively manipulating a String, because that’s all a path is. None of these access the file system except for mountpoint?, children,
each_child, realdirpath and realpath.
-
+
File status predicate methods
These methods are a facade for FileTest: * blockdev? * chardev? * directory? * executable? * executable_real? * exist? * file? * grpowned? * owned? * pipe? * readable? * world_readable? * readable_real? * setgid? * setuid? * size * size? * socket? * sticky? * symlink? * writable? * world_writable? * writable_real? * zero?
File property and manipulation methods
These methods are a facade for File: * each_line(args, &block) read(args) binread(args) readlines(args) sysopen(args) write(args) binwrite(args) atime * birthtime * ctime * mtime * chmod(mode) * lchmod(mode) * chown(owner, group) * lchown(owner, group) * fnmatch(pattern, args) fnmatch?(pattern, args) ftype * make_link(old) * open(args, &block) readlink * rename(to) * stat * lstat * make_symlink(old) * truncate(length) * utime(atime, mtime) * lutime(atime, mtime) * basename(args) dirname * extname * expand_path(args) split
Directory methods
These methods are a facade for Dir: * Pathname.glob(args) Pathname.getwd / Pathname.pwd * rmdir * entries * each_entry(&block) * mkdir(args) opendir(*args)
Utilities
These methods are a mixture of Find, FileUtils, and others: * find(&block) * mkpath * rmtree * unlink / delete
Method documentation
As the above section shows, most of the methods in Pathname are facades. The documentation for these methods generally just says, for instance, “See FileTest.writable?”, as you should be familiar with the original method anyway, and its documentation (e.g. through ri) will contain more information. In some cases, a brief description will follow.
Constants
- SAME_PATHS
- SEPARATOR_LIST
-
Separator list string.
- SEPARATOR_PAT
-
Regexpthat matches a separator. - TO_PATH
Public Class Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 199
def self.getwd: () -> Pathname
(String | Array[String] pattern, ?Integer flags) → Array[Pathname]
(String | Array[String] pattern, ?Integer flags) { (Pathname) → untyped } → nil
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 207
def self.glob: (String | Array[String] pattern, ?Integer flags) -> Array[Pathname]
| (String | Array[String] pattern, ?Integer flags) { (Pathname) -> untyped } -> nil
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1278
def initialize: (string | Pathname) -> void
Create a Pathname object from the given String (or String-like object). If path contains a NUL character (\0), an ArgumentError is raised.
Public Instance Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 235
def +: (Pathname | String | _ToStr other) -> Pathname
Appends a pathname fragment to self to produce a new Pathname object. Since other is considered as a path relative to self, if other is an absolute path, the new Pathname object is created from just other.
p1 = Pathname.new("/usr") # Pathname:/usr p2 = p1 + "bin/ruby" # Pathname:/usr/bin/ruby p3 = p1 + "/etc/passwd" # Pathname:/etc/passwd # / is aliased to +. p4 = p1 / "bin/ruby" # Pathname:/usr/bin/ruby p5 = p1 / "/etc/passwd" # Pathname:/etc/passwd
This method doesn’t access the file system; it is pure string manipulation.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 256
def <=>: (Pathname other) -> Integer
| (untyped other) -> nil
Provides a case-sensitive comparison operator for pathnames.
Pathname.new('/usr') <=> Pathname.new('/usr/bin') #=> -1 Pathname.new('/usr/bin') <=> Pathname.new('/usr/bin') #=> 0 Pathname.new('/usr/bin') <=> Pathname.new('/USR/BIN') #=> 1
It will return -1, 0 or 1 depending on the value of the left argument relative to the right argument. Or it will return nil if the arguments are not comparable.
(untyped) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 267
def ==: (untyped) -> bool
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.
(untyped) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 269
def ===: (untyped) -> bool
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 287
def absolute?: () -> bool
Predicate method for testing whether a path is absolute.
It returns true if the pathname begins with a slash.
p = Pathname.new('/im/sure') p.absolute? #=> true p = Pathname.new('not/so/sure') p.absolute? #=> false
(untyped path) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1259
def add_trailing_separator: (untyped path) -> untyped
() { (Pathname) → untyped } → nil
() → Enumerator[Pathname, nil]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 318
def ascend: () { (Pathname) -> untyped } -> nil
| () -> Enumerator[Pathname, nil]
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>
Returns an Enumerator if no block was given.
enum = Pathname.new("/usr/bin/ruby").ascend
# ... do stuff ...
enum.each { |e| ... }
# yields Pathnames /usr/bin/ruby, /usr/bin, /usr, and /.
It doesn’t access the filesystem.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 327
def atime: () -> Time
See File.atime. Returns last access time.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 335
def basename: (?String | _ToStr suffix) -> Pathname
See File.basename. Returns the last component of the path.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 344
def binread: (?Integer length, ?Integer offset) -> String
See File.binread. Returns all the bytes from the file, or the first N if specified.
(String, ?Integer offset, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: Hash[String, String] | Proc | Method, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) → Integer
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 354
def binwrite: (String, ?Integer offset, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: Hash[String, String] | Proc | Method, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) -> Integer
Writes contents to the file, opening it in binary mode.
See File.binwrite.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 365
def birthtime: () -> Time
Returns the birth time for the file. If the platform doesn’t have birthtime, raises NotImplementedError.
See File.birthtime.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 373
def blockdev?: () -> bool
See FileTest.blockdev?.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 381
def chardev?: () -> bool
See FileTest.chardev?.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 406
def children: (?boolish with_directory) -> Array[Pathname]
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 results never contain the entries . and .. in the directory because they are not children.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 414
def chmod: (Integer mode_int) -> Integer
See File.chmod. Changes permissions.
(untyped path) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1261
def chop_basename: (untyped path) -> untyped
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 422
def chown: (Integer owner, Integer group) -> Integer
See File.chown. Change owner and group of file.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 438
def cleanpath: (?boolish consider_symlink) -> Pathname
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 Pathname#realpath.
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1263
def cleanpath_aggressive: () -> untyped
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1265
def cleanpath_conservative: () -> untyped
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 447
def ctime: () -> Time
See File.ctime. Returns last (directory entry, not file) change time.
(untyped path) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1267
def del_trailing_separator: (untyped path) -> untyped
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 454
def delete: () -> Integer
() { (Pathname) → untyped } → nil
() → Enumerator[Pathname, nil]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 485
def descend: () { (Pathname) -> untyped } -> nil
| () -> Enumerator[Pathname, nil]
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>
Returns an Enumerator if no block was given.
enum = Pathname.new("/usr/bin/ruby").descend
# ... do stuff ...
enum.each { |e| ... }
# yields Pathnames /, /usr, /usr/bin, and /usr/bin/ruby.
It doesn’t access the filesystem.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 494
def directory?: () -> bool
See FileTest.directory?.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 503
def dirname: () -> Pathname
See File.dirname. Returns all but the last component of the path.
(?boolish with_directory) { (Pathname) → void } → Array[Pathname]
(?boolish with_directory) → Enumerator[Pathname, Array[Pathname]]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 545
def each_child: (?boolish with_directory) { (Pathname) -> void } -> Array[Pathname]
| (?boolish with_directory) -> Enumerator[Pathname, Array[Pathname]]
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>
Note that the results never contain the entries . and .. in the directory because they are not children.
() { (Pathname) → untyped } → nil
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 557
def each_entry: () { (Pathname) -> untyped } -> nil
Iterates over the entries (files and subdirectories) in the directory. It yields a Pathname object for each entry.
This method has existed since 1.8.1.
() { (String) → untyped } → nil
() → Enumerator[String, nil]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 575
def each_filename: () { (String) -> untyped } -> nil
| () -> Enumerator[String, nil]
Iterates over each component of the path.
Pathname.new("/usr/bin/ruby").each_filename {|filename| ... }
# yields "usr", "bin", and "ruby".
Returns an Enumerator if no block was given.
enum = Pathname.new("/usr/bin/ruby").each_filename
# ... do stuff ...
enum.each { |e| ... }
# yields "usr", "bin", and "ruby".
(?String sep, ?Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) { (String) → untyped } → nil
(Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) { (String) → untyped } → nil
(?String sep, ?Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) → Enumerator[String, nil]
(Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) → Enumerator[String, nil]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 587
def each_line: (?String sep, ?Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) { (String) -> untyped } -> nil
| (Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) { (String) -> untyped } -> nil
| (?String sep, ?Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) -> Enumerator[String, nil]
| (Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) -> Enumerator[String, nil]
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 600
def empty?: () -> bool
Tests the file is empty.
See Dir#empty? and FileTest.empty?.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 609
def entries: () -> Array[Pathname]
Return the entries (files and subdirectories) in the directory, each as a Pathname object.
(untyped) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 616
def eql?: (untyped) -> bool
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 624
def executable?: () -> bool
See FileTest.executable?.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 632
def executable_real?: () -> bool
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 640
def exist?: () -> bool
See FileTest.exist?.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 648
def expand_path: (?String dir) -> Pathname
See File.expand_path.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 656
def extname: () -> String
See File.extname. Returns the file’s extension.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 664
def file?: () -> bool
See FileTest.file?.
(?ignore_error: boolish) { (Pathname) → untyped } → nil
(?ignore_error: boolish) → Enumerator[Pathname, nil]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/stdlib/pathname/0/pathname.rbs, line 22
def find: (?ignore_error: boolish) { (Pathname) -> untyped } -> nil
| (?ignore_error: boolish) -> Enumerator[Pathname, nil]
Iterates over the directory tree in a depth first manner, yielding a Pathname for each file under “this” directory.
Note that you need to require ‘pathname’ to use this method.
Returns an Enumerator if no block is given.
Since it is implemented by the standard library module Find, Find.prune can be used to control the traversal.
If self is ., yielded pathnames begin with a filename in the current directory, not ./.
See Find.find
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 673
def fnmatch: (String pattern, ?Integer flags) -> bool
See File.fnmatch. Return true if the receiver matches the given pattern.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 689
def freeze: () -> Pathname
Freze self.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 698
def ftype: () -> String
See File.ftype. Returns “type” of file (“file”, “directory”, etc).
(String | Array[String] pattern, ?Integer flags) → Array[Pathname]
(String | Array[String] pattern, ?Integer flags) { (Pathname) → untyped } → nil
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 711
def glob: (String | Array[String] pattern, ?Integer flags) -> Array[Pathname]
| (String | Array[String] pattern, ?Integer flags) { (Pathname) -> untyped } -> nil
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 720
def grpowned?: () -> bool
See FileTest.grpowned?.
(untyped path) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1269
def has_trailing_separator?: (untyped path) -> untyped
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 722
def hash: () -> Integer
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 724
def inspect: () -> String
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 741
def join: (*String | _ToStr | Pathname args) -> Pathname
Joins the given pathnames onto self to create a new Pathname object. This is effectively the same as using Pathname#+ to append self and all arguments sequentially.
path0 = Pathname.new("/usr") # Pathname:/usr path0 = path0.join("bin/ruby") # Pathname:/usr/bin/ruby # is the same as path1 = Pathname.new("/usr") + "bin/ruby" # Pathname:/usr/bin/ruby path0 == path1 #=> true
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 749
def lchmod: (Integer mode) -> Integer
See File.lchmod.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 757
def lchown: (Integer owner, Integer group) -> Integer
See File.lchown.
() → ::File::Stat
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 765
def lstat: () -> ::File::Stat
See File.lstat.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 777
def lutime: (Time | Numeric atime, Time | Numeric mtime) -> Integer
Update the access and modification times of the file.
Same as Pathname#utime, but does not follow symbolic links.
See File.lutime.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 785
def make_link: (String | Pathname | _ToStr old) -> Integer
See File.link. Creates a hard link.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 793
def make_symlink: (String | Pathname | _ToStr old) -> Integer
See File.symlink. Creates a symbolic link.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 801
def mkdir: (?Integer perm) -> Integer
See Dir.mkdir. Create the referenced directory.
() → self
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 812
def mkpath: () -> self
Creates a full path, including any intermediate directories that don’t yet exist.
See FileUtils.mkpath and FileUtils.mkdir_p
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 820
def mountpoint?: () -> bool
Returns true if self points to a mountpoint.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 828
def mtime: () -> Time
See File.mtime. Returns last modification time.
(?string | int mode, ?int perm, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?path: path, ?invalid: :replace | nil, ?undef: :replace | nil, ?replace: String | nil, ?fallback: Hash[string, string] | ^(String) → string | Method | nil, ?xml: :text | :attr | nil, ?cr_newline: bool, ?crlf_newline: bool, ?universal_newline: bool) → File
[T] (?string | int mode, ?int perm, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?path: path, ?invalid: :replace | nil, ?undef: :replace | nil, ?replace: String | nil, ?fallback: Hash[string, string] | ^(String) → string | Method | nil, ?xml: :text | :attr | nil, ?cr_newline: bool, ?crlf_newline: bool, ?universal_newline: bool) { (File) → T } → T
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 836
def open: (
?string | int mode,
?int perm,
# open options
?flags: Integer,
?external_encoding: encoding,
?internal_encoding: encoding,
?encoding: encoding,
?textmode: boolish,
?binmode: boolish,
?autoclose: boolish,
?path: path,
# encoding options
?invalid: :replace | nil,
?undef: :replace | nil,
?replace: String | nil,
?fallback: Hash[string, string] | ^(String) -> string | Method | nil,
?xml: :text | :attr | nil,
?cr_newline: bool,
?crlf_newline: bool,
?universal_newline: bool
) -> File
| [T] (
?string | int mode,
?int perm,
# open options
?mode: Integer | String,
?flags: Integer,
?external_encoding: encoding,
?internal_encoding: encoding,
?encoding: encoding,
?textmode: boolish,
?binmode: boolish,
?autoclose: boolish,
?path: path,
# encoding options
?invalid: :replace | nil,
?undef: :replace | nil,
?replace: String | nil,
?fallback: Hash[string, string] | ^(String) -> string | Method | nil,
?xml: :text | :attr | nil,
?cr_newline: bool,
?crlf_newline: bool,
?universal_newline: bool
) { (File) -> T } -> T
See File.open. Opens the file for reading or writing.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 888
def opendir: () -> Dir
| [U] () { (Dir) -> U } -> U
See Dir.open.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 897
def owned?: () -> bool
See FileTest.owned?.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 907
def parent: () -> Pathname
Returns the parent directory.
This is same as self + '..'.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 915
def pipe?: () -> bool
See FileTest.pipe?.
(untyped path1, untyped path2) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1280
def plus: (untyped path1, untyped path2) -> untyped
(untyped prefix, untyped relpath) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1282
def prepend_prefix: (untyped prefix, untyped relpath) -> untyped
(?Integer length, ?Integer offset, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish) → String
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 924
def read: (?Integer length, ?Integer offset, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish) -> String
See File.read. Returns all data from the file, or the first N bytes if specified.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 932
def readable?: () -> bool
See FileTest.readable?.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 940
def readable_real?: () -> bool
(?String sep, ?Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) → Array[String]
(Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) → Array[String]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 948
def readlines: (?String sep, ?Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) -> Array[String]
| (Integer limit, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?chomp: boolish) -> Array[String]
See File.readlines. Returns all the lines from the file.
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 957
def readlink: () -> untyped
See File.readlink. Read symbolic link.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 969
def realdirpath: (?string | Pathname base_dir) -> Pathname
Returns the real (absolute) pathname of self in the actual filesystem.
Does not contain symlinks or useless dots, .. and ..
The last component of the real pathname can be nonexistent.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 981
def realpath: (?string | Pathname base_dir) -> Pathname
Returns the real (absolute) pathname for self in the actual filesystem.
Does not contain symlinks or useless dots, .. and ..
All components of the pathname must exist when this method is called.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 999
def relative?: () -> bool
The opposite of Pathname#absolute?
It returns false if the pathname begins with a slash.
p = Pathname.new('/im/sure') p.relative? #=> false p = Pathname.new('not/so/sure') p.relative? #=> true
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1018
def relative_path_from: (Pathname | string base_directory) -> Pathname
Returns a relative path from the given base_directory to the receiver.
If self is absolute, then base_directory must be absolute too.
If self is relative, then base_directory must be relative too.
This method doesn’t access the filesystem. It assumes no symlinks.
ArgumentError is raised when it cannot find a relative path.
Note that this method does not handle situations where the case sensitivity of the filesystem in use differs from the operating system default.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1026
def rename: (Pathname | string new_name) -> 0
See File.rename. Rename the file.
() → 0
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1034
def rmdir: () -> 0
See Dir.rmdir. Remove the referenced directory.
() → self
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/stdlib/pathname/0/pathname.rbs, line 35
def rmtree: () -> self
Recursively deletes a directory, including all directories beneath it.
Note that you need to require ‘pathname’ to use this method.
See FileUtils.rm_rf
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1046
def root?: () -> bool
Predicate method for root directories. Returns true if the pathname consists of consecutive slashes.
It doesn’t access the filesystem. So it may return false for some pathnames which points to roots such as /usr/...
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1054
def setgid?: () -> bool
See FileTest.setgid?.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1062
def setuid?: () -> bool
See FileTest.setuid?.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1070
def size: () -> Integer
See FileTest.size.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1078
def size?: () -> Integer?
See FileTest.size?.
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1086
def socket?: () -> untyped
See FileTest.socket?.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1095
def split: () -> [ Pathname, Pathname ]
(untyped path) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1284
def split_names: (untyped path) -> untyped
() → File::Stat
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1103
def stat: () -> File::Stat
See File.stat. Returns a File::Stat object.
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1111
def sticky?: () -> untyped
See FileTest.sticky?.
(Regexp | string pattern, string | Hash[String, String] replacement) → Pathname
(Regexp | string pattern) { (String match) → string } → Pathname
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1123
def sub: (Regexp | string pattern, string | Hash[String, String] replacement) -> Pathname
| (Regexp | string pattern) { (String match) -> string } -> Pathname
Return a pathname which is substituted by String#sub.
path1 = Pathname.new('/usr/bin/perl') path1.sub('perl', 'ruby') #=> #<Pathname:/usr/bin/ruby>
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1137
def sub_ext: (string replacement) -> Pathname
Return a pathname with repl added as a suffix to the basename.
If self has no extension part, repl is appended.
Pathname.new('/usr/bin/shutdown').sub_ext('.rb') #=> #<Pathname:/usr/bin/shutdown.rb>
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1145
def symlink?: () -> untyped
See FileTest.symlink?.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1153
def sysopen: (?String mode, ?Integer perm) -> Integer
See File.sysopen.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1161
def taint: () -> Pathname
Returns pathname. This method is deprecated and will be removed in Ruby 3.2.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1166
def to_path: () -> String
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1182
def truncate: (Integer length) -> 0
See File.truncate. Truncate the file to length bytes.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1191
def unlink: () -> Integer
Removes a file or directory, using File.unlink or Dir.unlink as necessary.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1199
def untaint: () -> Pathname
Returns pathname. This method is deprecated and will be removed in Ruby 3.2.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1207
def utime: (Integer | Time atime, Integer | Time mtime) -> Integer
See File.utime. Update the access and modification times.
() → (Integer | nil)
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1215
def world_readable?: () -> (Integer | nil)
() → (Integer | nil)
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1223
def world_writable?: () -> (Integer | nil)
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1231
def writable?: () -> bool
See FileTest.writable?.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1239
def writable_real?: () -> bool
(String content, ?Integer offset, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish) → Integer
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1247
def write: (String content, ?Integer offset, ?mode: Integer | String, ?flags: Integer, ?external_encoding: encoding, ?internal_encoding: encoding, ?encoding: encoding, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish) -> Integer
Writes contents to the file. See File.write.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.1.3/core/pathname.rbs, line 1255
def zero?: () -> bool
See FileTest.zero?.