rbs 3.0.0.dev.2 → 3.0.0.dev.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -1
  3. data/.github/workflows/ruby.yml +4 -0
  4. data/Gemfile.lock +11 -11
  5. data/Rakefile +2 -2
  6. data/Steepfile +1 -1
  7. data/core/array.rbs +573 -423
  8. data/core/basic_object.rbs +11 -39
  9. data/core/binding.rbs +1 -1
  10. data/core/builtin.rbs +8 -0
  11. data/core/class.rbs +37 -0
  12. data/core/comparable.rbs +7 -18
  13. data/core/complex.rbs +2 -2
  14. data/core/data.rbs +419 -0
  15. data/core/dir.rbs +52 -104
  16. data/core/encoding.rbs +22 -181
  17. data/core/enumerable.rbs +212 -175
  18. data/core/enumerator/product.rbs +96 -0
  19. data/core/enumerator.rbs +57 -8
  20. data/core/errors.rbs +8 -2
  21. data/core/exception.rbs +41 -0
  22. data/core/fiber.rbs +95 -12
  23. data/core/file.rbs +840 -275
  24. data/core/file_test.rbs +34 -19
  25. data/core/float.rbs +40 -96
  26. data/core/gc.rbs +15 -3
  27. data/core/hash.rbs +113 -175
  28. data/core/integer.rbs +85 -145
  29. data/core/io/buffer.rbs +187 -60
  30. data/core/io/wait.rbs +28 -16
  31. data/core/io.rbs +1859 -1389
  32. data/core/kernel.rbs +525 -961
  33. data/core/match_data.rbs +306 -142
  34. data/core/math.rbs +506 -234
  35. data/core/method.rbs +0 -24
  36. data/core/module.rbs +110 -17
  37. data/core/nil_class.rbs +2 -0
  38. data/core/numeric.rbs +76 -144
  39. data/core/object.rbs +88 -212
  40. data/core/proc.rbs +17 -5
  41. data/core/process.rbs +22 -5
  42. data/core/ractor.rbs +1 -1
  43. data/core/random.rbs +20 -3
  44. data/core/range.rbs +91 -89
  45. data/core/rational.rbs +2 -3
  46. data/core/rbs/unnamed/argf.rbs +177 -120
  47. data/core/rbs/unnamed/env_class.rbs +89 -163
  48. data/core/rbs/unnamed/random.rbs +36 -12
  49. data/core/refinement.rbs +8 -0
  50. data/core/regexp.rbs +462 -272
  51. data/core/ruby_vm.rbs +210 -0
  52. data/{stdlib/set/0 → core}/set.rbs +43 -47
  53. data/core/string.rbs +1403 -1332
  54. data/core/string_io.rbs +191 -107
  55. data/core/struct.rbs +67 -63
  56. data/core/symbol.rbs +187 -201
  57. data/core/thread.rbs +40 -35
  58. data/core/time.rbs +902 -826
  59. data/core/trace_point.rbs +55 -6
  60. data/core/unbound_method.rbs +48 -24
  61. data/docs/collection.md +4 -0
  62. data/docs/syntax.md +55 -0
  63. data/ext/rbs_extension/parser.c +5 -6
  64. data/lib/rbs/cli.rb +6 -1
  65. data/lib/rbs/collection/cleaner.rb +8 -1
  66. data/lib/rbs/collection/config/lockfile.rb +3 -1
  67. data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
  68. data/lib/rbs/collection/config.rb +1 -1
  69. data/lib/rbs/collection/sources/git.rb +9 -2
  70. data/lib/rbs/collection/sources/local.rb +79 -0
  71. data/lib/rbs/collection/sources.rb +8 -1
  72. data/lib/rbs/environment.rb +6 -5
  73. data/lib/rbs/environment_loader.rb +3 -2
  74. data/lib/rbs/errors.rb +18 -0
  75. data/lib/rbs/locator.rb +26 -7
  76. data/lib/rbs/sorter.rb +2 -2
  77. data/lib/rbs/version.rb +1 -1
  78. data/sig/collection/sources.rbs +32 -3
  79. data/sig/environment.rbs +2 -3
  80. data/sig/locator.rbs +14 -2
  81. data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
  82. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
  83. data/stdlib/cgi/0/core.rbs +16 -0
  84. data/stdlib/coverage/0/coverage.rbs +50 -8
  85. data/stdlib/csv/0/csv.rbs +1 -1
  86. data/stdlib/date/0/date.rbs +856 -726
  87. data/stdlib/date/0/date_time.rbs +83 -210
  88. data/stdlib/erb/0/erb.rbs +13 -36
  89. data/stdlib/etc/0/etc.rbs +127 -20
  90. data/stdlib/fileutils/0/fileutils.rbs +1290 -381
  91. data/stdlib/logger/0/logger.rbs +466 -316
  92. data/stdlib/net-http/0/net-http.rbs +2211 -534
  93. data/stdlib/nkf/0/nkf.rbs +5 -5
  94. data/stdlib/objspace/0/objspace.rbs +31 -14
  95. data/stdlib/openssl/0/openssl.rbs +11 -7
  96. data/stdlib/optparse/0/optparse.rbs +20 -17
  97. data/stdlib/pathname/0/pathname.rbs +21 -4
  98. data/stdlib/pstore/0/pstore.rbs +378 -154
  99. data/stdlib/pty/0/pty.rbs +24 -8
  100. data/stdlib/ripper/0/ripper.rbs +1650 -0
  101. data/stdlib/socket/0/addrinfo.rbs +9 -15
  102. data/stdlib/socket/0/socket.rbs +36 -3
  103. data/stdlib/strscan/0/string_scanner.rbs +7 -5
  104. data/stdlib/tempfile/0/tempfile.rbs +104 -44
  105. data/stdlib/time/0/time.rbs +2 -2
  106. data/stdlib/uri/0/file.rbs +5 -0
  107. data/stdlib/uri/0/generic.rbs +2 -2
  108. data/stdlib/yaml/0/yaml.rbs +2 -2
  109. data/stdlib/zlib/0/zlib.rbs +1 -1
  110. metadata +8 -6
  111. data/core/deprecated.rbs +0 -9
  112. data/sig/shims/ripper.rbs +0 -8
data/core/file.rbs CHANGED
@@ -1,328 +1,880 @@
1
1
  # <!-- rdoc-file=file.c -->
2
- # A File is an abstraction of any file object accessible by the program and is
3
- # closely associated with class IO. File includes the methods of module
4
- # FileTest as class methods, allowing you to write (for example)
5
- # `File.exist?("foo")`.
6
- #
7
- # In the description of File methods, *permission bits* are a platform-specific
8
- # set of bits that indicate permissions of a file. On Unix-based systems,
9
- # permissions are viewed as a set of three octets, for the owner, the group, and
10
- # the rest of the world. For each of these entities, permissions may be set to
11
- # read, write, or execute the file:
12
- #
13
- # The permission bits `0644` (in octal) would thus be interpreted as read/write
14
- # for owner, and read-only for group and other. Higher-order bits may also be
15
- # used to indicate the type of file (plain, directory, pipe, socket, and so on)
16
- # and various other special features. If the permissions are for a directory,
17
- # the meaning of the execute bit changes; when set the directory can be
18
- # searched.
19
- #
20
- # On non-Posix operating systems, there may be only the ability to make a file
21
- # read-only or read-write. In this case, the remaining permission bits will be
22
- # synthesized to resemble typical values. For instance, on Windows NT the
23
- # default permission bits are `0644`, which means read/write for owner,
24
- # read-only for all others. The only change that can be made is to make the file
25
- # read-only, which is reported as `0444`.
26
- #
27
- # Various constants for the methods in File can be found in File::Constants.
2
+ # A File object is a representation of a file in the underlying platform.
28
3
  #
29
- # ## What's Here
4
+ # Class File extends module FileTest, supporting such singleton methods as
5
+ # `File.exist?`.
30
6
  #
31
- # First, what's elsewhere. Class File:
7
+ # ### About the Examples
32
8
  #
33
- # * Inherits from [class IO](IO.html#class-IO-label-What-27s+Here), in
34
- # particular, methods for creating, reading, and writing files
35
- # * Includes [module
36
- # FileTest](FileTest.html#module-FileTest-label-What-27s+Here). which
37
- # provides dozens of additional methods.
9
+ # Many examples here use these variables:
38
10
  #
11
+ # # English text with newlines.
12
+ # text = <<~EOT
13
+ # First line
14
+ # Second line
39
15
  #
40
- # Here, class File provides methods that are useful for:
16
+ # Fourth line
17
+ # Fifth line
18
+ # EOT
41
19
  #
42
- # * [Creating](#class-File-label-Creating)
43
- # * [Querying](#class-File-label-Querying)
44
- # * [Settings](#class-File-label-Settings)
45
- # * [Other](#class-File-label-Other)
20
+ # # Russian text.
21
+ # russian = "\u{442 435 441 442}" # => "тест"
46
22
  #
23
+ # # Binary data.
24
+ # data = "\u9990\u9991\u9992\u9993\u9994"
47
25
  #
48
- # ### Creating
26
+ # # Text file.
27
+ # File.write('t.txt', text)
49
28
  #
50
- # ::new
51
- # : Opens the file at the given path; returns the file.
29
+ # # File with Russian text.
30
+ # File.write('t.rus', russian)
52
31
  #
53
- # ::open
54
- # : Same as ::new, but when given a block will yield the file to the
55
- # block, and close the file upon exiting the block.
32
+ # # File with binary data.
33
+ # f = File.new('t.dat', 'wb:UTF-16')
34
+ # f.write(data)
35
+ # f.close
56
36
  #
57
- # ::link
58
- # : Creates a new name for an existing file using a hard link.
37
+ # ## Access Modes
59
38
  #
60
- # ::mkfifo
61
- # : Returns the FIFO file created at the given path.
39
+ # Methods File.new and File.open each create a File object for a given file
40
+ # path.
62
41
  #
63
- # ::symlink
64
- # : Creates a symbolic link for the given file path.
42
+ # ### String Access Modes
65
43
  #
44
+ # Methods File.new and File.open each may take string argument `mode`, which:
66
45
  #
46
+ # * Begins with a 1- or 2-character [read/write
47
+ # mode](rdoc-ref:File@Read-2FWrite+Mode).
48
+ # * May also contain a 1-character [data mode](rdoc-ref:File@Data+Mode).
49
+ # * May also contain a 1-character [file-create
50
+ # mode](rdoc-ref:File@File-Create+Mode).
67
51
  #
68
- # ### Querying
69
52
  #
70
- # *Paths*
53
+ # #### Read/Write Mode
71
54
  #
72
- # ::absolute_path
73
- # : Returns the absolute file path for the given path.
55
+ # The read/write `mode` determines:
74
56
  #
75
- # ::absolute_path?
76
- # : Returns whether the given path is the absolute file path.
57
+ # * Whether the file is to be initially truncated.
77
58
  #
78
- # ::basename
79
- # : Returns the last component of the given file path.
59
+ # * Whether reading is allowed, and if so:
80
60
  #
81
- # ::dirname
82
- # : Returns all but the last component of the given file path.
61
+ # * The initial read position in the file.
62
+ # * Where in the file reading can occur.
83
63
  #
84
- # ::expand_path
85
- # : Returns the absolute file path for the given path, expanding `~` for a
86
- # home directory.
87
64
  #
88
- # ::extname
89
- # : Returns the file extension for the given file path.
65
+ # * Whether writing is allowed, and if so:
90
66
  #
91
- # ::fnmatch? (aliased as ::fnmatch)
92
- # : Returns whether the given file path matches the given pattern.
67
+ # * The initial write position in the file.
68
+ # * Where in the file writing can occur.
93
69
  #
94
- # ::join
95
- # : Joins path components into a single path string.
96
70
  #
97
- # ::path
98
- # : Returns the string representation of the given path.
99
71
  #
100
- # ::readlink
101
- # : Returns the path to the file at the given symbolic link.
72
+ # These tables summarize:
102
73
  #
103
- # ::realdirpath
104
- # : Returns the real path for the given file path, where the last
105
- # component need not exist.
74
+ # Read/Write Modes for Existing File
106
75
  #
107
- # ::realpath
108
- # : Returns the real path for the given file path, where all components
109
- # must exist.
76
+ # |------|-----------|----------|----------|----------|-----------|
77
+ # | R/W | Initial | | Initial | | Initial |
78
+ # | Mode | Truncate? | Read | Read Pos | Write | Write Pos |
79
+ # |------|-----------|----------|----------|----------|-----------|
80
+ # | 'r' | No | Anywhere | 0 | Error | - |
81
+ # | 'w' | Yes | Error | - | Anywhere | 0 |
82
+ # | 'a' | No | Error | - | End only | End |
83
+ # | 'r+' | No | Anywhere | 0 | Anywhere | 0 |
84
+ # | 'w+' | Yes | Anywhere | 0 | Anywhere | 0 |
85
+ # | 'a+' | No | Anywhere | End | End only | End |
86
+ # |------|-----------|----------|----------|----------|-----------|
110
87
  #
111
- # ::split
112
- # : Returns an array of two strings: the directory name and basename of
113
- # the file at the given path.
88
+ # Read/Write Modes for \File To Be Created
114
89
  #
115
- # #path (aliased as #to_path)
116
- # : Returns the string representation of the given path.
90
+ # |------|----------|----------|----------|-----------|
91
+ # | R/W | | Initial | | Initial |
92
+ # | Mode | Read | Read Pos | Write | Write Pos |
93
+ # |------|----------|----------|----------|-----------|
94
+ # | 'w' | Error | - | Anywhere | 0 |
95
+ # | 'a' | Error | - | End only | 0 |
96
+ # | 'w+' | Anywhere | 0 | Anywhere | 0 |
97
+ # | 'a+' | Anywhere | 0 | End only | End |
98
+ # |------|----------|----------|----------|-----------|
117
99
  #
100
+ # Note that modes `'r'` and `'r+'` are not allowed for a non-existent file
101
+ # (exception raised).
118
102
  #
103
+ # In the tables:
119
104
  #
120
- # *Times*
105
+ # * `Anywhere` means that methods IO#rewind, IO#pos=, and IO#seek may be used
106
+ # to change the file's position, so that allowed reading or writing may
107
+ # occur anywhere in the file.
108
+ # * `End only` means that writing can occur only at end-of-file, and that
109
+ # methods IO#rewind, IO#pos=, and IO#seek do not affect writing.
110
+ # * `Error` means that an exception is raised if disallowed reading or writing
111
+ # is attempted.
121
112
  #
122
- # ::atime
123
- # : Returns a Time for the most recent access to the given file.
124
113
  #
125
- # ::birthtime
126
- # : Returns a Time for the creation of the given file.
114
+ # ##### Read/Write Modes for Existing File
127
115
  #
128
- # ::ctime
129
- # : Returns a Time for the metadata change of the given file.
116
+ # * `'r'`:
130
117
  #
131
- # ::mtime
132
- # : Returns a Time for the most recent data modification to the content of
133
- # the given file.
118
+ # * File is not initially truncated:
134
119
  #
135
- # #atime
136
- # : Returns a Time for the most recent access to `self`.
120
+ # f = File.new('t.txt') # => #<File:t.txt>
121
+ # f.size == 0 # => false
137
122
  #
138
- # #birthtime
139
- # : Returns a Time the creation for `self`.
123
+ # * File's initial read position is 0:
140
124
  #
141
- # #ctime
142
- # : Returns a Time for the metadata change of `self`.
125
+ # f.pos # => 0
143
126
  #
144
- # #mtime
145
- # : Returns a Time for the most recent data modification to the content of
146
- # `self`.
127
+ # * File may be read anywhere; see IO#rewind, IO#pos=, IO#seek:
147
128
  #
129
+ # f.readline # => "First line\n"
130
+ # f.readline # => "Second line\n"
148
131
  #
132
+ # f.rewind
133
+ # f.readline # => "First line\n"
149
134
  #
150
- # *Types*
135
+ # f.pos = 1
136
+ # f.readline # => "irst line\n"
151
137
  #
152
- # ::blockdev?
153
- # : Returns whether the file at the given path is a block device.
138
+ # f.seek(1, :CUR)
139
+ # f.readline # => "econd line\n"
154
140
  #
155
- # ::chardev?
156
- # : Returns whether the file at the given path is a character device.
141
+ # * Writing is not allowed:
157
142
  #
158
- # ::directory?
159
- # : Returns whether the file at the given path is a diretory.
143
+ # f.write('foo') # Raises IOError.
160
144
  #
161
- # ::executable?
162
- # : Returns whether the file at the given path is executable by the
163
- # effective user and group of the current process.
164
145
  #
165
- # ::executable_real?
166
- # : Returns whether the file at the given path is executable by the real
167
- # user and group of the current process.
146
+ # * `'w'`:
168
147
  #
169
- # ::exist?
170
- # : Returns whether the file at the given path exists.
148
+ # * File is initially truncated:
171
149
  #
172
- # ::file?
173
- # : Returns whether the file at the given path is a regular file.
150
+ # path = 't.tmp'
151
+ # File.write(path, text)
152
+ # f = File.new(path, 'w')
153
+ # f.size == 0 # => true
174
154
  #
175
- # ::ftype
176
- # : Returns a string giving the type of the file at the given path.
155
+ # * File's initial write position is 0:
177
156
  #
178
- # ::grpowned?
179
- # : Returns whether the effective group of the current process owns the
180
- # file at the given path.
157
+ # f.pos # => 0
181
158
  #
182
- # ::identical?
183
- # : Returns whether the files at two given paths are identical.
159
+ # * File may be written anywhere (even past end-of-file); see IO#rewind,
160
+ # IO#pos=, IO#seek:
184
161
  #
185
- # ::lstat
186
- # : Returns the File::Stat object for the last symbolic link in the given
187
- # path.
162
+ # f.write('foo')
163
+ # f.flush
164
+ # File.read(path) # => "foo"
165
+ # f.pos # => 3
188
166
  #
189
- # ::owned?
190
- # : Returns whether the effective user of the current process owns the
191
- # file at the given path.
167
+ # f.write('bar')
168
+ # f.flush
169
+ # File.read(path) # => "foobar"
170
+ # f.pos # => 6
192
171
  #
193
- # ::pipe?
194
- # : Returns whether the file at the given path is a pipe.
172
+ # f.rewind
173
+ # f.write('baz')
174
+ # f.flush
175
+ # File.read(path) # => "bazbar"
176
+ # f.pos # => 3
195
177
  #
196
- # ::readable?
197
- # : Returns whether the file at the given path is readable by the
198
- # effective user and group of the current process.
178
+ # f.pos = 3
179
+ # f.write('foo')
180
+ # f.flush
181
+ # File.read(path) # => "bazfoo"
182
+ # f.pos # => 6
199
183
  #
200
- # ::readable_real?
201
- # : Returns whether the file at the given path is readable by the real
202
- # user and group of the current process.
184
+ # f.seek(-3, :END)
185
+ # f.write('bam')
186
+ # f.flush
187
+ # File.read(path) # => "bazbam"
188
+ # f.pos # => 6
203
189
  #
204
- # ::setgid?
205
- # : Returns whether the setgid bit is set for the file at the given path.
190
+ # f.pos = 8
191
+ # f.write('bah') # Zero padding as needed.
192
+ # f.flush
193
+ # File.read(path) # => "bazbam\u0000\u0000bah"
194
+ # f.pos # => 11
206
195
  #
207
- # ::setuid?
208
- # : Returns whether the setuid bit is set for the file at the given path.
196
+ # * Reading is not allowed:
209
197
  #
210
- # ::socket?
211
- # : Returns whether the file at the given path is a socket.
198
+ # f.read # Raises IOError.
212
199
  #
213
- # ::stat
214
- # : Returns the File::Stat object for the file at the given path.
215
200
  #
216
- # ::sticky?
217
- # : Returns whether the file at the given path has its sticky bit set.
201
+ # * `'a'`:
218
202
  #
219
- # ::symlink?
220
- # : Returns whether the file at the given path is a symbolic link.
203
+ # * File is not initially truncated:
221
204
  #
222
- # ::umask
223
- # : Returns the umask value for the current process.
205
+ # path = 't.tmp'
206
+ # File.write(path, 'foo')
207
+ # f = File.new(path, 'a')
208
+ # f.size == 0 # => false
224
209
  #
225
- # ::world_readable?
226
- # : Returns whether the file at the given path is readable by others.
210
+ # * File's initial position is 0 (but is ignored):
227
211
  #
228
- # ::world_writable?
229
- # : Returns whether the file at the given path is writable by others.
212
+ # f.pos # => 0
230
213
  #
231
- # ::writable?
232
- # : Returns whether the file at the given path is writable by the
233
- # effective user and group of the current process.
214
+ # * File may be written only at end-of-file; IO#rewind, IO#pos=, IO#seek
215
+ # do not affect writing:
234
216
  #
235
- # ::writable_real?
236
- # : Returns whether the file at the given path is writable by the real
237
- # user and group of the current process.
217
+ # f.write('bar')
218
+ # f.flush
219
+ # File.read(path) # => "foobar"
220
+ # f.write('baz')
221
+ # f.flush
222
+ # File.read(path) # => "foobarbaz"
238
223
  #
239
- # #lstat
240
- # : Returns the File::Stat object for the last symbolic link in the path
241
- # for `self`.
224
+ # f.rewind
225
+ # f.write('bat')
226
+ # f.flush
227
+ # File.read(path) # => "foobarbazbat"
242
228
  #
229
+ # * Reading is not allowed:
243
230
  #
231
+ # f.read # Raises IOError.
244
232
  #
245
- # *Contents*
246
233
  #
247
- # ::empty? (aliased as ::zero?)
248
- # : Returns whether the file at the given path exists and is empty.
234
+ # * `'r+'`:
249
235
  #
250
- # ::size
251
- # : Returns the size (bytes) of the file at the given path.
236
+ # * File is not initially truncated:
252
237
  #
253
- # ::size?
254
- # : Returns `nil` if there is no file at the given path, or if that file
255
- # is empty; otherwise returns the file size (bytes).
238
+ # path = 't.tmp'
239
+ # File.write(path, text)
240
+ # f = File.new(path, 'r+')
241
+ # f.size == 0 # => false
256
242
  #
257
- # #size
258
- # : Returns the size (bytes) of `self`.
243
+ # * File's initial read position is 0:
259
244
  #
245
+ # f.pos # => 0
260
246
  #
247
+ # * File may be read or written anywhere (even past end-of-file); see
248
+ # IO#rewind, IO#pos=, IO#seek:
261
249
  #
262
- # ### Settings
250
+ # f.readline # => "First line\n"
251
+ # f.readline # => "Second line\n"
263
252
  #
264
- # ::chmod
265
- # : Changes permissions of the file at the given path.
253
+ # f.rewind
254
+ # f.readline # => "First line\n"
266
255
  #
267
- # ::chown
268
- # : Change ownership of the file at the given path.
256
+ # f.pos = 1
257
+ # f.readline # => "irst line\n"
269
258
  #
270
- # ::lchmod
271
- # : Changes permissions of the last symbolic link in the given path.
259
+ # f.seek(1, :CUR)
260
+ # f.readline # => "econd line\n"
272
261
  #
273
- # ::lchown
274
- # : Change ownership of the last symbolic in the given path.
262
+ # f.rewind
263
+ # f.write('WWW')
264
+ # f.flush
265
+ # File.read(path)
266
+ # # => "WWWst line\nSecond line\nFourth line\nFifth line\n"
275
267
  #
276
- # ::lutime
277
- # : For each given file path, sets the access time and modification time
278
- # of the last symbolic link in the path.
268
+ # f.pos = 10
269
+ # f.write('XXX')
270
+ # f.flush
271
+ # File.read(path)
272
+ # # => "WWWst lineXXXecond line\nFourth line\nFifth line\n"
279
273
  #
280
- # ::rename
281
- # : Moves the file at one given path to another given path.
274
+ # f.seek(-6, :END)
275
+ # # => 0
276
+ # f.write('YYY')
277
+ # # => 3
278
+ # f.flush
279
+ # # => #<File:t.tmp>
280
+ # File.read(path)
281
+ # # => "WWWst lineXXXecond line\nFourth line\nFifth YYYe\n"
282
282
  #
283
- # ::utime
284
- # : Sets the access time and modification time of each file at the given
285
- # paths.
283
+ # f.seek(2, :END)
284
+ # f.write('ZZZ') # Zero padding as needed.
285
+ # f.flush
286
+ # File.read(path)
287
+ # # => "WWWst lineXXXecond line\nFourth line\nFifth YYYe\n\u0000\u0000ZZZ"
286
288
  #
287
- # #flock
288
- # : Locks or unlocks `self`.
289
289
  #
290
+ # * `'a+'`:
290
291
  #
292
+ # * File is not initially truncated:
291
293
  #
292
- # ### Other
294
+ # path = 't.tmp'
295
+ # File.write(path, 'foo')
296
+ # f = File.new(path, 'a+')
297
+ # f.size == 0 # => false
298
+ #
299
+ # * File's initial read position is 0:
300
+ #
301
+ # f.pos # => 0
302
+ #
303
+ # * File may be written only at end-of-file; IO#rewind, IO#pos=, IO#seek
304
+ # do not affect writing:
305
+ #
306
+ # f.write('bar')
307
+ # f.flush
308
+ # File.read(path) # => "foobar"
309
+ # f.write('baz')
310
+ # f.flush
311
+ # File.read(path) # => "foobarbaz"
312
+ #
313
+ # f.rewind
314
+ # f.write('bat')
315
+ # f.flush
316
+ # File.read(path) # => "foobarbazbat"
317
+ #
318
+ # * File may be read anywhere; see IO#rewind, IO#pos=, IO#seek:
319
+ #
320
+ # f.rewind
321
+ # f.read # => "foobarbazbat"
322
+ #
323
+ # f.pos = 3
324
+ # f.read # => "barbazbat"
325
+ #
326
+ # f.seek(-3, :END)
327
+ # f.read # => "bat"
328
+ #
329
+ #
330
+ #
331
+ # ##### Read/Write Modes for File To Be Created
332
+ #
333
+ # Note that modes `'r'` and `'r+'` are not allowed for a non-existent file
334
+ # (exception raised).
335
+ #
336
+ # * `'w'`:
337
+ #
338
+ # * File's initial write position is 0:
339
+ #
340
+ # path = 't.tmp'
341
+ # FileUtils.rm_f(path)
342
+ # f = File.new(path, 'w')
343
+ # f.pos # => 0
344
+ #
345
+ # * File may be written anywhere (even past end-of-file); see IO#rewind,
346
+ # IO#pos=, IO#seek:
347
+ #
348
+ # f.write('foo')
349
+ # f.flush
350
+ # File.read(path) # => "foo"
351
+ # f.pos # => 3
352
+ #
353
+ # f.write('bar')
354
+ # f.flush
355
+ # File.read(path) # => "foobar"
356
+ # f.pos # => 6
357
+ #
358
+ # f.rewind
359
+ # f.write('baz')
360
+ # f.flush
361
+ # File.read(path) # => "bazbar"
362
+ # f.pos # => 3
363
+ #
364
+ # f.pos = 3
365
+ # f.write('foo')
366
+ # f.flush
367
+ # File.read(path) # => "bazfoo"
368
+ # f.pos # => 6
369
+ #
370
+ # f.seek(-3, :END)
371
+ # f.write('bam')
372
+ # f.flush
373
+ # File.read(path) # => "bazbam"
374
+ # f.pos # => 6
375
+ #
376
+ # f.pos = 8
377
+ # f.write('bah') # Zero padding as needed.
378
+ # f.flush
379
+ # File.read(path) # => "bazbam\u0000\u0000bah"
380
+ # f.pos # => 11
381
+ #
382
+ # * Reading is not allowed:
383
+ #
384
+ # f.read # Raises IOError.
385
+ #
386
+ #
387
+ # * `'a'`:
388
+ #
389
+ # * File's initial write position is 0:
390
+ #
391
+ # path = 't.tmp'
392
+ # FileUtils.rm_f(path)
393
+ # f = File.new(path, 'a')
394
+ # f.pos # => 0
395
+ #
396
+ # * Writing occurs only at end-of-file:
397
+ #
398
+ # f.write('foo')
399
+ # f.pos # => 3
400
+ # f.write('bar')
401
+ # f.pos # => 6
402
+ # f.flush
403
+ # File.read(path) # => "foobar"
404
+ #
405
+ # f.rewind
406
+ # f.write('baz')
407
+ # f.flush
408
+ # File.read(path) # => "foobarbaz"
409
+ #
410
+ # * Reading is not allowed:
411
+ #
412
+ # f.read # Raises IOError.
413
+ #
414
+ #
415
+ # * `'w+'`:
416
+ #
417
+ # * File's initial position is 0:
418
+ #
419
+ # path = 't.tmp'
420
+ # FileUtils.rm_f(path)
421
+ # f = File.new(path, 'w+')
422
+ # f.pos # => 0
423
+ #
424
+ # * File may be written anywhere (even past end-of-file); see IO#rewind,
425
+ # IO#pos=, IO#seek:
426
+ #
427
+ # f.write('foo')
428
+ # f.flush
429
+ # File.read(path) # => "foo"
430
+ # f.pos # => 3
431
+ #
432
+ # f.write('bar')
433
+ # f.flush
434
+ # File.read(path) # => "foobar"
435
+ # f.pos # => 6
436
+ #
437
+ # f.rewind
438
+ # f.write('baz')
439
+ # f.flush
440
+ # File.read(path) # => "bazbar"
441
+ # f.pos # => 3
442
+ #
443
+ # f.pos = 3
444
+ # f.write('foo')
445
+ # f.flush
446
+ # File.read(path) # => "bazfoo"
447
+ # f.pos # => 6
448
+ #
449
+ # f.seek(-3, :END)
450
+ # f.write('bam')
451
+ # f.flush
452
+ # File.read(path) # => "bazbam"
453
+ # f.pos # => 6
454
+ #
455
+ # f.pos = 8
456
+ # f.write('bah') # Zero padding as needed.
457
+ # f.flush
458
+ # File.read(path) # => "bazbam\u0000\u0000bah"
459
+ # f.pos # => 11
460
+ #
461
+ # * File may be read anywhere (even past end-of-file); see IO#rewind,
462
+ # IO#pos=, IO#seek:
463
+ #
464
+ # f.rewind
465
+ # # => 0
466
+ # f.read
467
+ # # => "bazbam\u0000\u0000bah"
468
+ #
469
+ # f.pos = 3
470
+ # # => 3
471
+ # f.read
472
+ # # => "bam\u0000\u0000bah"
473
+ #
474
+ # f.seek(-3, :END)
475
+ # # => 0
476
+ # f.read
477
+ # # => "bah"
478
+ #
479
+ #
480
+ # * `'a+'`:
481
+ #
482
+ # * File's initial write position is 0:
483
+ #
484
+ # path = 't.tmp'
485
+ # FileUtils.rm_f(path)
486
+ # f = File.new(path, 'a+')
487
+ # f.pos # => 0
488
+ #
489
+ # * Writing occurs only at end-of-file:
490
+ #
491
+ # f.write('foo')
492
+ # f.pos # => 3
493
+ # f.write('bar')
494
+ # f.pos # => 6
495
+ # f.flush
496
+ # File.read(path) # => "foobar"
497
+ #
498
+ # f.rewind
499
+ # f.write('baz')
500
+ # f.flush
501
+ # File.read(path) # => "foobarbaz"
502
+ #
503
+ # * File may be read anywhere (even past end-of-file); see IO#rewind,
504
+ # IO#pos=, IO#seek:
505
+ #
506
+ # f.rewind
507
+ # f.read # => "foobarbaz"
508
+ #
509
+ # f.pos = 3
510
+ # f.read # => "barbaz"
511
+ #
512
+ # f.seek(-3, :END)
513
+ # f.read # => "baz"
514
+ #
515
+ # f.pos = 800
516
+ # f.read # => ""
517
+ #
518
+ #
519
+ #
520
+ # #### Data Mode
521
+ #
522
+ # To specify whether data is to be treated as text or as binary data, either of
523
+ # the following may be suffixed to any of the string read/write modes above:
524
+ #
525
+ # * `'t'`: Text data; sets the default external encoding to `Encoding::UTF_8`;
526
+ # on Windows, enables conversion between EOL and CRLF and enables
527
+ # interpreting `0x1A` as an end-of-file marker.
528
+ # * `'b'`: Binary data; sets the default external encoding to
529
+ # `Encoding::ASCII_8BIT`; on Windows, suppresses conversion between EOL and
530
+ # CRLF and disables interpreting `0x1A` as an end-of-file marker.
531
+ #
532
+ #
533
+ # If neither is given, the stream defaults to text data.
534
+ #
535
+ # Examples:
536
+ #
537
+ # File.new('t.txt', 'rt')
538
+ # File.new('t.dat', 'rb')
539
+ #
540
+ # When the data mode is specified, the read/write mode may not be omitted, and
541
+ # the data mode must precede the file-create mode, if given:
542
+ #
543
+ # File.new('t.dat', 'b') # Raises an exception.
544
+ # File.new('t.dat', 'rxb') # Raises an exception.
545
+ #
546
+ # #### File-Create Mode
547
+ #
548
+ # The following may be suffixed to any writable string mode above:
549
+ #
550
+ # * `'x'`: Creates the file if it does not exist; raises an exception if the
551
+ # file exists.
552
+ #
553
+ #
554
+ # Example:
555
+ #
556
+ # File.new('t.tmp', 'wx')
557
+ #
558
+ # When the file-create mode is specified, the read/write mode may not be
559
+ # omitted, and the file-create mode must follow the data mode:
560
+ #
561
+ # File.new('t.dat', 'x') # Raises an exception.
562
+ # File.new('t.dat', 'rxb') # Raises an exception.
293
563
  #
294
- # ::truncate
295
- # : Truncates the file at the given file path to the given size.
564
+ # ### Integer Access Modes
296
565
  #
297
- # ::unlink (aliased as ::delete)
298
- # : Deletes the file for each given file path.
566
+ # When mode is an integer it must be one or more of the following constants,
567
+ # which may be combined by the bitwise OR operator `|`:
299
568
  #
300
- # #truncate
301
- # : Truncates `self` to the given size.
569
+ # * `File::RDONLY`: Open for reading only.
570
+ # * `File::WRONLY`: Open for writing only.
571
+ # * `File::RDWR`: Open for reading and writing.
572
+ # * `File::APPEND`: Open for appending only.
573
+ #
574
+ #
575
+ # Examples:
576
+ #
577
+ # File.new('t.txt', File::RDONLY)
578
+ # File.new('t.tmp', File::RDWR | File::CREAT | File::EXCL)
579
+ #
580
+ # Note: Method IO#set_encoding does not allow the mode to be specified as an
581
+ # integer.
582
+ #
583
+ # ### File-Create Mode Specified as an Integer
584
+ #
585
+ # These constants may also be ORed into the integer mode:
586
+ #
587
+ # * `File::CREAT`: Create file if it does not exist.
588
+ # * `File::EXCL`: Raise an exception if `File::CREAT` is given and the file
589
+ # exists.
590
+ #
591
+ #
592
+ # ### Data Mode Specified as an Integer
593
+ #
594
+ # Data mode cannot be specified as an integer. When the stream access mode is
595
+ # given as an integer, the data mode is always text, never binary.
596
+ #
597
+ # Note that although there is a constant `File::BINARY`, setting its value in an
598
+ # integer stream mode has no effect; this is because, as documented in
599
+ # File::Constants, the `File::BINARY` value disables line code conversion, but
600
+ # does not change the external encoding.
601
+ #
602
+ # ### Encodings
603
+ #
604
+ # Any of the string modes above may specify encodings - either external encoding
605
+ # only or both external and internal encodings - by appending one or both
606
+ # encoding names, separated by colons:
607
+ #
608
+ # f = File.new('t.dat', 'rb')
609
+ # f.external_encoding # => #<Encoding:ASCII-8BIT>
610
+ # f.internal_encoding # => nil
611
+ # f = File.new('t.dat', 'rb:UTF-16')
612
+ # f.external_encoding # => #<Encoding:UTF-16 (dummy)>
613
+ # f.internal_encoding # => nil
614
+ # f = File.new('t.dat', 'rb:UTF-16:UTF-16')
615
+ # f.external_encoding # => #<Encoding:UTF-16 (dummy)>
616
+ # f.internal_encoding # => #<Encoding:UTF-16>
617
+ # f.close
618
+ #
619
+ # The numerous encoding names are available in array Encoding.name_list:
620
+ #
621
+ # Encoding.name_list.take(3) # => ["ASCII-8BIT", "UTF-8", "US-ASCII"]
622
+ #
623
+ # When the external encoding is set, strings read are tagged by that encoding
624
+ # when reading, and strings written are converted to that encoding when writing.
625
+ #
626
+ # When both external and internal encodings are set, strings read are converted
627
+ # from external to internal encoding, and strings written are converted from
628
+ # internal to external encoding. For further details about transcoding input and
629
+ # output, see [Encodings](rdoc-ref:encodings.rdoc@Encodings).
630
+ #
631
+ # If the external encoding is `'BOM|UTF-8'`, `'BOM|UTF-16LE'` or
632
+ # `'BOM|UTF16-BE'`, Ruby checks for a Unicode BOM in the input document to help
633
+ # determine the encoding. For UTF-16 encodings the file open mode must be
634
+ # binary. If the BOM is found, it is stripped and the external encoding from the
635
+ # BOM is used.
636
+ #
637
+ # Note that the BOM-style encoding option is case insensitive, so `'bom|utf-8'`
638
+ # is also valid.
639
+ #
640
+ # ## File Permissions
641
+ #
642
+ # A File object has *permissions*, an octal integer representing the permissions
643
+ # of an actual file in the underlying platform.
644
+ #
645
+ # Note that file permissions are quite different from the *mode* of a file
646
+ # stream (File object). See IO@Modes.
647
+ #
648
+ # In a File object, the permissions are available thus, where method `mode`,
649
+ # despite its name, returns permissions:
650
+ #
651
+ # f = File.new('t.txt')
652
+ # f.lstat.mode.to_s(8) # => "100644"
653
+ #
654
+ # On a Unix-based operating system, the three low-order octal digits represent
655
+ # the permissions for owner (6), group (4), and world (4). The triplet of bits
656
+ # in each octal digit represent, respectively, read, write, and execute
657
+ # permissions.
658
+ #
659
+ # Permissions `0644` thus represent read-write access for owner and read-only
660
+ # access for group and world. See man pages
661
+ # [open(2)](https://www.unix.com/man-page/bsd/2/open) and
662
+ # [chmod(2)](https://www.unix.com/man-page/bsd/2/chmod).
663
+ #
664
+ # For a directory, the meaning of the execute bit changes: when set, the
665
+ # directory can be searched.
666
+ #
667
+ # Higher-order bits in permissions may indicate the type of file (plain,
668
+ # directory, pipe, socket, etc.) and various other special features.
669
+ #
670
+ # On non-Posix operating systems, permissions may include only read-only or
671
+ # read-write, in which case, the remaining permission will resemble typical
672
+ # values. On Windows, for instance, the default permissions are `0644`; The only
673
+ # change that can be made is to make the file read-only, which is reported as
674
+ # `0444`.
675
+ #
676
+ # For a method that actually creates a file in the underlying platform (as
677
+ # opposed to merely creating a File object), permissions may be specified:
678
+ #
679
+ # File.new('t.tmp', File::CREAT, 0644)
680
+ # File.new('t.tmp', File::CREAT, 0444)
681
+ #
682
+ # Permissions may also be changed:
683
+ #
684
+ # f = File.new('t.tmp', File::CREAT, 0444)
685
+ # f.chmod(0644)
686
+ # f.chmod(0444)
687
+ #
688
+ # ## File Constants
689
+ #
690
+ # Various constants for use in File and IO methods may be found in module
691
+ # File::Constants; an array of their names is returned by
692
+ # `File::Constants.constants`.
693
+ #
694
+ # ## What's Here
695
+ #
696
+ # First, what's elsewhere. Class File:
697
+ #
698
+ # * Inherits from [class IO](rdoc-ref:IO@What-27s+Here), in particular,
699
+ # methods for creating, reading, and writing files
700
+ # * Includes [module FileTest](rdoc-ref:FileTest@What-27s+Here). which
701
+ # provides dozens of additional methods.
702
+ #
703
+ #
704
+ # Here, class File provides methods that are useful for:
705
+ #
706
+ # * [Creating](rdoc-ref:File@Creating)
707
+ # * [Querying](rdoc-ref:File@Querying)
708
+ # * [Settings](rdoc-ref:File@Settings)
709
+ # * [Other](rdoc-ref:File@Other)
710
+ #
711
+ #
712
+ # ### Creating
713
+ #
714
+ # * ::new: Opens the file at the given path; returns the file.
715
+ # * ::open: Same as ::new, but when given a block will yield the file to the
716
+ # block, and close the file upon exiting the block.
717
+ # * ::link: Creates a new name for an existing file using a hard link.
718
+ # * ::mkfifo: Returns the FIFO file created at the given path.
719
+ # * ::symlink: Creates a symbolic link for the given file path.
720
+ #
721
+ #
722
+ # ### Querying
723
+ #
724
+ # *Paths*
725
+ #
726
+ # * ::absolute_path: Returns the absolute file path for the given path.
727
+ # * ::absolute_path?: Returns whether the given path is the absolute file
728
+ # path.
729
+ # * ::basename: Returns the last component of the given file path.
730
+ # * ::dirname: Returns all but the last component of the given file path.
731
+ # * ::expand_path: Returns the absolute file path for the given path,
732
+ # expanding `~` for a home directory.
733
+ # * ::extname: Returns the file extension for the given file path.
734
+ # * ::fnmatch? (aliased as ::fnmatch): Returns whether the given file path
735
+ # matches the given pattern.
736
+ # * ::join: Joins path components into a single path string.
737
+ # * ::path: Returns the string representation of the given path.
738
+ # * ::readlink: Returns the path to the file at the given symbolic link.
739
+ # * ::realdirpath: Returns the real path for the given file path, where the
740
+ # last component need not exist.
741
+ # * ::realpath: Returns the real path for the given file path, where all
742
+ # components must exist.
743
+ # * ::split: Returns an array of two strings: the directory name and basename
744
+ # of the file at the given path.
745
+ # * #path (aliased as #to_path): Returns the string representation of the
746
+ # given path.
747
+ #
748
+ #
749
+ # *Times*
750
+ #
751
+ # * ::atime: Returns a Time for the most recent access to the given file.
752
+ # * ::birthtime: Returns a Time for the creation of the given file.
753
+ # * ::ctime: Returns a Time for the metadata change of the given file.
754
+ # * ::mtime: Returns a Time for the most recent data modification to the
755
+ # content of the given file.
756
+ # * #atime: Returns a Time for the most recent access to `self`.
757
+ # * #birthtime: Returns a Time the creation for `self`.
758
+ # * #ctime: Returns a Time for the metadata change of `self`.
759
+ # * #mtime: Returns a Time for the most recent data modification to the
760
+ # content of `self`.
761
+ #
762
+ #
763
+ # *Types*
764
+ #
765
+ # * ::blockdev?: Returns whether the file at the given path is a block device.
766
+ # * ::chardev?: Returns whether the file at the given path is a character
767
+ # device.
768
+ # * ::directory?: Returns whether the file at the given path is a directory.
769
+ # * ::executable?: Returns whether the file at the given path is executable by
770
+ # the effective user and group of the current process.
771
+ # * ::executable_real?: Returns whether the file at the given path is
772
+ # executable by the real user and group of the current process.
773
+ # * ::exist?: Returns whether the file at the given path exists.
774
+ # * ::file?: Returns whether the file at the given path is a regular file.
775
+ # * ::ftype: Returns a string giving the type of the file at the given path.
776
+ # * ::grpowned?: Returns whether the effective group of the current process
777
+ # owns the file at the given path.
778
+ # * ::identical?: Returns whether the files at two given paths are identical.
779
+ # * ::lstat: Returns the File::Stat object for the last symbolic link in the
780
+ # given path.
781
+ # * ::owned?: Returns whether the effective user of the current process owns
782
+ # the file at the given path.
783
+ # * ::pipe?: Returns whether the file at the given path is a pipe.
784
+ # * ::readable?: Returns whether the file at the given path is readable by the
785
+ # effective user and group of the current process.
786
+ # * ::readable_real?: Returns whether the file at the given path is readable
787
+ # by the real user and group of the current process.
788
+ # * ::setgid?: Returns whether the setgid bit is set for the file at the given
789
+ # path.
790
+ # * ::setuid?: Returns whether the setuid bit is set for the file at the given
791
+ # path.
792
+ # * ::socket?: Returns whether the file at the given path is a socket.
793
+ # * ::stat: Returns the File::Stat object for the file at the given path.
794
+ # * ::sticky?: Returns whether the file at the given path has its sticky bit
795
+ # set.
796
+ # * ::symlink?: Returns whether the file at the given path is a symbolic link.
797
+ # * ::umask: Returns the umask value for the current process.
798
+ # * ::world_readable?: Returns whether the file at the given path is readable
799
+ # by others.
800
+ # * ::world_writable?: Returns whether the file at the given path is writable
801
+ # by others.
802
+ # * ::writable?: Returns whether the file at the given path is writable by the
803
+ # effective user and group of the current process.
804
+ # * ::writable_real?: Returns whether the file at the given path is writable
805
+ # by the real user and group of the current process.
806
+ # * #lstat: Returns the File::Stat object for the last symbolic link in the
807
+ # path for `self`.
808
+ #
809
+ #
810
+ # *Contents*
811
+ #
812
+ # * ::empty? (aliased as ::zero?): Returns whether the file at the given path
813
+ # exists and is empty.
814
+ # * ::size: Returns the size (bytes) of the file at the given path.
815
+ # * ::size?: Returns `nil` if there is no file at the given path, or if that
816
+ # file is empty; otherwise returns the file size (bytes).
817
+ # * #size: Returns the size (bytes) of `self`.
818
+ #
819
+ #
820
+ # ### Settings
821
+ #
822
+ # * ::chmod: Changes permissions of the file at the given path.
823
+ # * ::chown: Change ownership of the file at the given path.
824
+ # * ::lchmod: Changes permissions of the last symbolic link in the given path.
825
+ # * ::lchown: Change ownership of the last symbolic in the given path.
826
+ # * ::lutime: For each given file path, sets the access time and modification
827
+ # time of the last symbolic link in the path.
828
+ # * ::rename: Moves the file at one given path to another given path.
829
+ # * ::utime: Sets the access time and modification time of each file at the
830
+ # given paths.
831
+ # * #flock: Locks or unlocks `self`.
832
+ #
833
+ #
834
+ # ### Other
835
+ #
836
+ # * ::truncate: Truncates the file at the given file path to the given size.
837
+ # * ::unlink (aliased as ::delete): Deletes the file for each given file path.
838
+ # * #truncate: Truncates `self` to the given size.
302
839
  #
303
840
  class File < IO
304
841
  # <!--
305
842
  # rdoc-file=io.c
306
- # - File.new(filename, mode="r" [, opt]) -> file
307
- # - File.new(filename [, mode [, perm]] [, opt]) -> file
843
+ # - File.new(path, mode = 'r', perm = 0666, **opts) -> file
308
844
  # -->
309
- # Opens the file named by `filename` according to the given `mode` and returns a
310
- # new File object.
845
+ # Opens the file at the given `path` according to the given `mode`; creates and
846
+ # returns a new File object for that file.
311
847
  #
312
- # See IO.new for a description of `mode` and `opt`.
848
+ # The new File object is buffered mode (or non-sync mode), unless `filename` is
849
+ # a tty. See IO#flush, IO#fsync, IO#fdatasync, and IO#sync=.
313
850
  #
314
- # If a file is being created, permission bits may be given in `perm`. These
315
- # mode and permission bits are platform dependent; on Unix systems, see open(2)
316
- # and chmod(2) man pages for details.
851
+ # Argument `path` must be a valid file path:
317
852
  #
318
- # The new File object is buffered mode (or non-sync mode), unless `filename` is
319
- # a tty. See IO#flush, IO#fsync, IO#fdatasync, and IO#sync= about sync mode.
853
+ # f = File.new('/etc/fstab')
854
+ # f.close
855
+ # f = File.new('t.txt')
856
+ # f.close
857
+ #
858
+ # Optional argument `mode` (defaults to 'r') must specify a valid mode; see
859
+ # [Access Modes](rdoc-ref:File@Access+Modes):
860
+ #
861
+ # f = File.new('t.tmp', 'w')
862
+ # f.close
863
+ # f = File.new('t.tmp', File::RDONLY)
864
+ # f.close
320
865
  #
321
- # ### Examples
866
+ # Optional argument `perm` (defaults to 0666) must specify valid permissions see
867
+ # [File Permissions](rdoc-ref:File@File+Permissions):
322
868
  #
323
- # f = File.new("testfile", "r")
324
- # f = File.new("newfile", "w+")
325
- # f = File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)
869
+ # f = File.new('t.tmp', File::CREAT, 0644)
870
+ # f.close
871
+ # f = File.new('t.tmp', File::CREAT, 0444)
872
+ # f.close
873
+ #
874
+ # Optional keyword arguments `opts` specify:
875
+ #
876
+ # * [Open Options](rdoc-ref:IO@Open+Options).
877
+ # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
326
878
  #
327
879
  def initialize: (string | _ToPath | int file_name, ?string | int mode, ?int perm) -> File
328
880
 
@@ -387,21 +939,23 @@ class File < IO
387
939
 
388
940
  # <!--
389
941
  # rdoc-file=file.c
390
- # - File.blockdev?(file_name) -> true or false
942
+ # - File.blockdev?(filepath) -> true or false
391
943
  # -->
392
- # Returns `true` if the named file is a block device.
944
+ # Returns `true` if `filepath` points to a block device, `false` otherwise:
393
945
  #
394
- # *file_name* can be an IO object.
946
+ # File.blockdev?('/dev/sda1') # => true
947
+ # File.blockdev?(File.new('t.tmp')) # => false
395
948
  #
396
949
  def self.blockdev?: (string | _ToPath | IO file_name) -> bool
397
950
 
398
951
  # <!--
399
952
  # rdoc-file=file.c
400
- # - File.chardev?(file_name) -> true or false
953
+ # - File.chardev?(filepath) -> true or false
401
954
  # -->
402
- # Returns `true` if the named file is a character device.
955
+ # Returns `true` if `filepath` points to a character device, `false` otherwise.
403
956
  #
404
- # *file_name* can be an IO object.
957
+ # File.chardev?($stdin) # => true
958
+ # File.chardev?('t.txt') # => false
405
959
  #
406
960
  def self.chardev?: (string | _ToPath | IO file_name) -> bool
407
961
 
@@ -464,14 +1018,19 @@ class File < IO
464
1018
 
465
1019
  # <!--
466
1020
  # rdoc-file=file.c
467
- # - File.directory?(file_name) -> true or false
1021
+ # - File.directory?(path) -> true or false
468
1022
  # -->
469
- # Returns `true` if the named file is a directory, or a symlink that points at a
470
- # directory, and `false` otherwise.
1023
+ # With string `object` given, returns `true` if `path` is a string path leading
1024
+ # to a directory, or to a symbolic link to a directory; `false` otherwise:
471
1025
  #
472
- # *file_name* can be an IO object.
1026
+ # File.directory?('.') # => true
1027
+ # File.directory?('foo') # => false
1028
+ # File.symlink('.', 'dirlink') # => 0
1029
+ # File.directory?('dirlink') # => true
1030
+ # File.symlink('t,txt', 'filelink') # => 0
1031
+ # File.directory?('filelink') # => false
473
1032
  #
474
- # File.directory?(".")
1033
+ # Argument `path` can be an IO object.
475
1034
  #
476
1035
  def self.directory?: (string | _ToPath | IO path) -> bool
477
1036
 
@@ -806,15 +1365,14 @@ class File < IO
806
1365
 
807
1366
  # <!--
808
1367
  # rdoc-file=file.c
809
- # - File.lstat(file_name) -> stat
1368
+ # - File.lstat(filepath) -> stat
810
1369
  # -->
811
- # Same as File::stat, but does not follow the last symbolic link. Instead,
812
- # reports on the link itself.
1370
+ # Like File::stat, but does not follow the last symbolic link; instead, returns
1371
+ # a File::Stat object for the link itself.
813
1372
  #
814
- # File.symlink("testfile", "link2test") #=> 0
815
- # File.stat("testfile").size #=> 66
816
- # File.lstat("link2test").size #=> 8
817
- # File.stat("link2test").size #=> 66
1373
+ # File.symlink('t.txt', 'symlink')
1374
+ # File.stat('symlink').size # => 47
1375
+ # File.lstat('symlink').size # => 5
818
1376
  #
819
1377
  def self.lstat: (string | _ToPath file_name) -> File::Stat
820
1378
 
@@ -853,20 +1411,15 @@ class File < IO
853
1411
 
854
1412
  # <!--
855
1413
  # rdoc-file=io.c
856
- # - File.open(filename, mode="r" [, opt]) -> file
857
- # - File.open(filename [, mode [, perm]] [, opt]) -> file
858
- # - File.open(filename, mode="r" [, opt]) {|file| block } -> obj
859
- # - File.open(filename [, mode [, perm]] [, opt]) {|file| block } -> obj
1414
+ # - File.open(path, mode = 'r', perm = 0666, **opts) -> file
1415
+ # - File.open(path, mode = 'r', perm = 0666, **opts) {|f| ... } -> object
860
1416
  # -->
861
- # With no associated block, File.open is a synonym for File.new. If the optional
862
- # code block is given, it will be passed the opened `file` as an argument and
863
- # the File object will automatically be closed when the block terminates. The
864
- # value of the block will be returned from File.open.
1417
+ # Creates a new File object, via File.new with the given arguments.
865
1418
  #
866
- # If a file is being created, its initial permissions may be set using the
867
- # `perm` parameter. See File.new for further discussion.
1419
+ # With no block given, returns the File object.
868
1420
  #
869
- # See IO.new for a description of the `mode` and `opt` parameters.
1421
+ # With a block given, calls the block with the File object and returns the
1422
+ # block's value.
870
1423
  #
871
1424
  def self.open: (string | _ToPath | int file_name, ?string | int mode, ?int perm) -> instance
872
1425
  | [T] (string | _ToPath | int file_name, ?string | int mode, ?int perm) { (File) -> T } -> T
@@ -895,11 +1448,13 @@ class File < IO
895
1448
 
896
1449
  # <!--
897
1450
  # rdoc-file=file.c
898
- # - File.pipe?(file_name) -> true or false
1451
+ # - File.pipe?(filepath) -> true or false
899
1452
  # -->
900
- # Returns `true` if the named file is a pipe.
1453
+ # Returns `true` if `filepath` points to a pipe, `false` otherwise:
901
1454
  #
902
- # *file_name* can be an IO object.
1455
+ # File.mkfifo('tmp/fifo')
1456
+ # File.pipe?('tmp/fifo') # => true
1457
+ # File.pipe?('t.txt') # => false
903
1458
  #
904
1459
  def self.pipe?: (string | _ToPath | IO file_name) -> bool
905
1460
 
@@ -1021,11 +1576,13 @@ class File < IO
1021
1576
 
1022
1577
  # <!--
1023
1578
  # rdoc-file=file.c
1024
- # - File.socket?(file_name) -> true or false
1579
+ # - File.socket?(filepath) -> true or false
1025
1580
  # -->
1026
- # Returns `true` if the named file is a socket.
1581
+ # Returns `true` if `filepath` points to a socket, `false` otherwise:
1027
1582
  #
1028
- # *file_name* can be an IO object.
1583
+ # require 'socket'
1584
+ # File.socket?(Socket.new(:INET, :STREAM)) # => true
1585
+ # File.socket?(File.new('t.txt')) # => false
1029
1586
  #
1030
1587
  def self.socket?: (string | _ToPath | IO file_name) -> bool
1031
1588
 
@@ -1042,11 +1599,11 @@ class File < IO
1042
1599
 
1043
1600
  # <!--
1044
1601
  # rdoc-file=file.c
1045
- # - File.stat(file_name) -> stat
1602
+ # - File.stat(filepath) -> stat
1046
1603
  # -->
1047
- # Returns a File::Stat object for the named file (see File::Stat).
1604
+ # Returns a File::Stat object for the file at `filepath` (see File::Stat):
1048
1605
  #
1049
- # File.stat("testfile").mtime #=> Tue Apr 08 12:58:04 CDT 2003
1606
+ # File.stat('t.txt').class # => File::Stat
1050
1607
  #
1051
1608
  def self.stat: (string | _ToPath file_name) -> File::Stat
1052
1609
 
@@ -1074,9 +1631,13 @@ class File < IO
1074
1631
 
1075
1632
  # <!--
1076
1633
  # rdoc-file=file.c
1077
- # - File.symlink?(file_name) -> true or false
1634
+ # - File.symlink?(filepath) -> true or false
1078
1635
  # -->
1079
- # Returns `true` if the named file is a symbolic link.
1636
+ # Returns `true` if `filepath` points to a symbolic link, `false` otherwise:
1637
+ #
1638
+ # symlink = File.symlink('t.txt', 'symlink')
1639
+ # File.symlink?('symlink') # => true
1640
+ # File.symlink?('t.txt') # => false
1080
1641
  #
1081
1642
  def self.symlink?: (string | _ToPath file_name) -> bool
1082
1643
 
@@ -1311,16 +1872,15 @@ class File < IO
1311
1872
 
1312
1873
  # <!--
1313
1874
  # rdoc-file=file.c
1314
- # - file.lstat -> stat
1875
+ # - lstat -> stat
1315
1876
  # -->
1316
- # Same as IO#stat, but does not follow the last symbolic link. Instead, reports
1317
- # on the link itself.
1877
+ # Like File#stat, but does not follow the last symbolic link; instead, returns a
1878
+ # File::Stat object for the link itself:
1318
1879
  #
1319
- # File.symlink("testfile", "link2test") #=> 0
1320
- # File.stat("testfile").size #=> 66
1321
- # f = File.new("link2test")
1322
- # f.lstat.size #=> 8
1323
- # f.stat.size #=> 66
1880
+ # File.symlink('t.txt', 'symlink')
1881
+ # f = File.new('symlink')
1882
+ # f.stat.size # => 47
1883
+ # f.lstat.size # => 11
1324
1884
  #
1325
1885
  def lstat: () -> (File::Stat | nil)
1326
1886
 
@@ -1522,7 +2082,7 @@ class File::Stat < Object
1522
2082
 
1523
2083
  # <!--
1524
2084
  # rdoc-file=file.c
1525
- # - stat.birthtime -> aTime
2085
+ # - stat.birthtime -> time
1526
2086
  # -->
1527
2087
  # Returns the birth time for *stat*.
1528
2088
  #
@@ -1589,7 +2149,7 @@ class File::Stat < Object
1589
2149
 
1590
2150
  # <!--
1591
2151
  # rdoc-file=file.c
1592
- # - stat.ctime -> aTime
2152
+ # - stat.ctime -> time
1593
2153
  # -->
1594
2154
  # Returns the change time for *stat* (that is, the time directory information
1595
2155
  # about the file was changed, not the file itself).
@@ -1634,14 +2194,19 @@ class File::Stat < Object
1634
2194
 
1635
2195
  # <!--
1636
2196
  # rdoc-file=file.c
1637
- # - File.directory?(file_name) -> true or false
2197
+ # - File.directory?(path) -> true or false
1638
2198
  # -->
1639
- # Returns `true` if the named file is a directory, or a symlink that points at a
1640
- # directory, and `false` otherwise.
2199
+ # With string `object` given, returns `true` if `path` is a string path leading
2200
+ # to a directory, or to a symbolic link to a directory; `false` otherwise:
1641
2201
  #
1642
- # *file_name* can be an IO object.
2202
+ # File.directory?('.') # => true
2203
+ # File.directory?('foo') # => false
2204
+ # File.symlink('.', 'dirlink') # => 0
2205
+ # File.directory?('dirlink') # => true
2206
+ # File.symlink('t,txt', 'filelink') # => 0
2207
+ # File.directory?('filelink') # => false
1643
2208
  #
1644
- # File.directory?(".")
2209
+ # Argument `path` can be an IO object.
1645
2210
  #
1646
2211
  def directory?: () -> bool
1647
2212
 
@@ -1703,7 +2268,7 @@ class File::Stat < Object
1703
2268
  # - stat.grpowned? -> true or false
1704
2269
  # -->
1705
2270
  # Returns true if the effective group id of the process is the same as the group
1706
- # id of *stat*. On Windows NT, returns `false`.
2271
+ # id of *stat*. On Windows, returns `false`.
1707
2272
  #
1708
2273
  # File.stat("testfile").grpowned? #=> true
1709
2274
  # File.stat("/etc/passwd").grpowned? #=> false
@@ -1751,7 +2316,7 @@ class File::Stat < Object
1751
2316
 
1752
2317
  # <!--
1753
2318
  # rdoc-file=file.c
1754
- # - stat.mtime -> aTime
2319
+ # - stat.mtime -> time
1755
2320
  # -->
1756
2321
  # Returns the modification time of *stat*.
1757
2322
  #