rbs 3.0.0.dev.2 → 3.0.0.dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -1
- data/.github/workflows/ruby.yml +4 -0
- data/Gemfile.lock +11 -11
- data/Rakefile +2 -2
- data/Steepfile +1 -1
- data/core/array.rbs +573 -423
- data/core/basic_object.rbs +11 -39
- data/core/binding.rbs +1 -1
- data/core/builtin.rbs +8 -0
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +7 -18
- data/core/complex.rbs +2 -2
- data/core/data.rbs +419 -0
- data/core/dir.rbs +52 -104
- data/core/encoding.rbs +22 -181
- data/core/enumerable.rbs +212 -175
- data/core/enumerator/product.rbs +96 -0
- data/core/enumerator.rbs +57 -8
- data/core/errors.rbs +8 -2
- data/core/exception.rbs +41 -0
- data/core/fiber.rbs +95 -12
- data/core/file.rbs +840 -275
- data/core/file_test.rbs +34 -19
- data/core/float.rbs +40 -96
- data/core/gc.rbs +15 -3
- data/core/hash.rbs +113 -175
- data/core/integer.rbs +85 -145
- data/core/io/buffer.rbs +187 -60
- data/core/io/wait.rbs +28 -16
- data/core/io.rbs +1859 -1389
- data/core/kernel.rbs +525 -961
- data/core/match_data.rbs +306 -142
- data/core/math.rbs +506 -234
- data/core/method.rbs +0 -24
- data/core/module.rbs +110 -17
- data/core/nil_class.rbs +2 -0
- data/core/numeric.rbs +76 -144
- data/core/object.rbs +88 -212
- data/core/proc.rbs +17 -5
- data/core/process.rbs +22 -5
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +20 -3
- data/core/range.rbs +91 -89
- data/core/rational.rbs +2 -3
- data/core/rbs/unnamed/argf.rbs +177 -120
- data/core/rbs/unnamed/env_class.rbs +89 -163
- data/core/rbs/unnamed/random.rbs +36 -12
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +462 -272
- data/core/ruby_vm.rbs +210 -0
- data/{stdlib/set/0 → core}/set.rbs +43 -47
- data/core/string.rbs +1403 -1332
- data/core/string_io.rbs +191 -107
- data/core/struct.rbs +67 -63
- data/core/symbol.rbs +187 -201
- data/core/thread.rbs +40 -35
- data/core/time.rbs +902 -826
- data/core/trace_point.rbs +55 -6
- data/core/unbound_method.rbs +48 -24
- data/docs/collection.md +4 -0
- data/docs/syntax.md +55 -0
- data/ext/rbs_extension/parser.c +5 -6
- data/lib/rbs/cli.rb +6 -1
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +3 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
- data/lib/rbs/collection/config.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +9 -2
- data/lib/rbs/collection/sources/local.rb +79 -0
- data/lib/rbs/collection/sources.rb +8 -1
- data/lib/rbs/environment.rb +6 -5
- data/lib/rbs/environment_loader.rb +3 -2
- data/lib/rbs/errors.rb +18 -0
- data/lib/rbs/locator.rb +26 -7
- data/lib/rbs/sorter.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/sig/collection/sources.rbs +32 -3
- data/sig/environment.rbs +2 -3
- data/sig/locator.rbs +14 -2
- data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
- data/stdlib/cgi/0/core.rbs +16 -0
- data/stdlib/coverage/0/coverage.rbs +50 -8
- data/stdlib/csv/0/csv.rbs +1 -1
- data/stdlib/date/0/date.rbs +856 -726
- data/stdlib/date/0/date_time.rbs +83 -210
- data/stdlib/erb/0/erb.rbs +13 -36
- data/stdlib/etc/0/etc.rbs +127 -20
- data/stdlib/fileutils/0/fileutils.rbs +1290 -381
- data/stdlib/logger/0/logger.rbs +466 -316
- data/stdlib/net-http/0/net-http.rbs +2211 -534
- data/stdlib/nkf/0/nkf.rbs +5 -5
- data/stdlib/objspace/0/objspace.rbs +31 -14
- data/stdlib/openssl/0/openssl.rbs +11 -7
- data/stdlib/optparse/0/optparse.rbs +20 -17
- data/stdlib/pathname/0/pathname.rbs +21 -4
- data/stdlib/pstore/0/pstore.rbs +378 -154
- data/stdlib/pty/0/pty.rbs +24 -8
- data/stdlib/ripper/0/ripper.rbs +1650 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -15
- data/stdlib/socket/0/socket.rbs +36 -3
- data/stdlib/strscan/0/string_scanner.rbs +7 -5
- data/stdlib/tempfile/0/tempfile.rbs +104 -44
- data/stdlib/time/0/time.rbs +2 -2
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/yaml/0/yaml.rbs +2 -2
- data/stdlib/zlib/0/zlib.rbs +1 -1
- metadata +8 -6
- data/core/deprecated.rbs +0 -9
- 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
|
|
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
|
-
#
|
|
4
|
+
# Class File extends module FileTest, supporting such singleton methods as
|
|
5
|
+
# `File.exist?`.
|
|
30
6
|
#
|
|
31
|
-
#
|
|
7
|
+
# ### About the Examples
|
|
32
8
|
#
|
|
33
|
-
#
|
|
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
|
-
#
|
|
16
|
+
# Fourth line
|
|
17
|
+
# Fifth line
|
|
18
|
+
# EOT
|
|
41
19
|
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
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
|
-
#
|
|
26
|
+
# # Text file.
|
|
27
|
+
# File.write('t.txt', text)
|
|
49
28
|
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
29
|
+
# # File with Russian text.
|
|
30
|
+
# File.write('t.rus', russian)
|
|
52
31
|
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
32
|
+
# # File with binary data.
|
|
33
|
+
# f = File.new('t.dat', 'wb:UTF-16')
|
|
34
|
+
# f.write(data)
|
|
35
|
+
# f.close
|
|
56
36
|
#
|
|
57
|
-
#
|
|
58
|
-
# : Creates a new name for an existing file using a hard link.
|
|
37
|
+
# ## Access Modes
|
|
59
38
|
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
39
|
+
# Methods File.new and File.open each create a File object for a given file
|
|
40
|
+
# path.
|
|
62
41
|
#
|
|
63
|
-
#
|
|
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
|
-
#
|
|
53
|
+
# #### Read/Write Mode
|
|
71
54
|
#
|
|
72
|
-
#
|
|
73
|
-
# : Returns the absolute file path for the given path.
|
|
55
|
+
# The read/write `mode` determines:
|
|
74
56
|
#
|
|
75
|
-
#
|
|
76
|
-
# : Returns whether the given path is the absolute file path.
|
|
57
|
+
# * Whether the file is to be initially truncated.
|
|
77
58
|
#
|
|
78
|
-
#
|
|
79
|
-
# : Returns the last component of the given file path.
|
|
59
|
+
# * Whether reading is allowed, and if so:
|
|
80
60
|
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
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
|
-
#
|
|
89
|
-
# : Returns the file extension for the given file path.
|
|
65
|
+
# * Whether writing is allowed, and if so:
|
|
90
66
|
#
|
|
91
|
-
#
|
|
92
|
-
#
|
|
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
|
-
#
|
|
101
|
-
# : Returns the path to the file at the given symbolic link.
|
|
72
|
+
# These tables summarize:
|
|
102
73
|
#
|
|
103
|
-
#
|
|
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
|
-
#
|
|
108
|
-
#
|
|
109
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
116
|
-
#
|
|
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
|
-
# *
|
|
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
|
-
#
|
|
126
|
-
# : Returns a Time for the creation of the given file.
|
|
114
|
+
# ##### Read/Write Modes for Existing File
|
|
127
115
|
#
|
|
128
|
-
#
|
|
129
|
-
# : Returns a Time for the metadata change of the given file.
|
|
116
|
+
# * `'r'`:
|
|
130
117
|
#
|
|
131
|
-
#
|
|
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
|
-
#
|
|
136
|
-
#
|
|
120
|
+
# f = File.new('t.txt') # => #<File:t.txt>
|
|
121
|
+
# f.size == 0 # => false
|
|
137
122
|
#
|
|
138
|
-
#
|
|
139
|
-
# : Returns a Time the creation for `self`.
|
|
123
|
+
# * File's initial read position is 0:
|
|
140
124
|
#
|
|
141
|
-
#
|
|
142
|
-
# : Returns a Time for the metadata change of `self`.
|
|
125
|
+
# f.pos # => 0
|
|
143
126
|
#
|
|
144
|
-
# #
|
|
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
|
-
#
|
|
135
|
+
# f.pos = 1
|
|
136
|
+
# f.readline # => "irst line\n"
|
|
151
137
|
#
|
|
152
|
-
#
|
|
153
|
-
#
|
|
138
|
+
# f.seek(1, :CUR)
|
|
139
|
+
# f.readline # => "econd line\n"
|
|
154
140
|
#
|
|
155
|
-
#
|
|
156
|
-
# : Returns whether the file at the given path is a character device.
|
|
141
|
+
# * Writing is not allowed:
|
|
157
142
|
#
|
|
158
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
170
|
-
# : Returns whether the file at the given path exists.
|
|
148
|
+
# * File is initially truncated:
|
|
171
149
|
#
|
|
172
|
-
#
|
|
173
|
-
#
|
|
150
|
+
# path = 't.tmp'
|
|
151
|
+
# File.write(path, text)
|
|
152
|
+
# f = File.new(path, 'w')
|
|
153
|
+
# f.size == 0 # => true
|
|
174
154
|
#
|
|
175
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
183
|
-
# :
|
|
159
|
+
# * File may be written anywhere (even past end-of-file); see IO#rewind,
|
|
160
|
+
# IO#pos=, IO#seek:
|
|
184
161
|
#
|
|
185
|
-
#
|
|
186
|
-
#
|
|
187
|
-
#
|
|
162
|
+
# f.write('foo')
|
|
163
|
+
# f.flush
|
|
164
|
+
# File.read(path) # => "foo"
|
|
165
|
+
# f.pos # => 3
|
|
188
166
|
#
|
|
189
|
-
#
|
|
190
|
-
#
|
|
191
|
-
#
|
|
167
|
+
# f.write('bar')
|
|
168
|
+
# f.flush
|
|
169
|
+
# File.read(path) # => "foobar"
|
|
170
|
+
# f.pos # => 6
|
|
192
171
|
#
|
|
193
|
-
#
|
|
194
|
-
#
|
|
172
|
+
# f.rewind
|
|
173
|
+
# f.write('baz')
|
|
174
|
+
# f.flush
|
|
175
|
+
# File.read(path) # => "bazbar"
|
|
176
|
+
# f.pos # => 3
|
|
195
177
|
#
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#
|
|
178
|
+
# f.pos = 3
|
|
179
|
+
# f.write('foo')
|
|
180
|
+
# f.flush
|
|
181
|
+
# File.read(path) # => "bazfoo"
|
|
182
|
+
# f.pos # => 6
|
|
199
183
|
#
|
|
200
|
-
#
|
|
201
|
-
#
|
|
202
|
-
#
|
|
184
|
+
# f.seek(-3, :END)
|
|
185
|
+
# f.write('bam')
|
|
186
|
+
# f.flush
|
|
187
|
+
# File.read(path) # => "bazbam"
|
|
188
|
+
# f.pos # => 6
|
|
203
189
|
#
|
|
204
|
-
#
|
|
205
|
-
#
|
|
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
|
-
#
|
|
208
|
-
# : Returns whether the setuid bit is set for the file at the given path.
|
|
196
|
+
# * Reading is not allowed:
|
|
209
197
|
#
|
|
210
|
-
#
|
|
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
|
-
#
|
|
217
|
-
# : Returns whether the file at the given path has its sticky bit set.
|
|
201
|
+
# * `'a'`:
|
|
218
202
|
#
|
|
219
|
-
#
|
|
220
|
-
# : Returns whether the file at the given path is a symbolic link.
|
|
203
|
+
# * File is not initially truncated:
|
|
221
204
|
#
|
|
222
|
-
#
|
|
223
|
-
#
|
|
205
|
+
# path = 't.tmp'
|
|
206
|
+
# File.write(path, 'foo')
|
|
207
|
+
# f = File.new(path, 'a')
|
|
208
|
+
# f.size == 0 # => false
|
|
224
209
|
#
|
|
225
|
-
#
|
|
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
|
-
#
|
|
229
|
-
# : Returns whether the file at the given path is writable by others.
|
|
212
|
+
# f.pos # => 0
|
|
230
213
|
#
|
|
231
|
-
#
|
|
232
|
-
#
|
|
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
|
-
#
|
|
236
|
-
#
|
|
237
|
-
#
|
|
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
|
-
#
|
|
240
|
-
#
|
|
241
|
-
#
|
|
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
|
-
#
|
|
248
|
-
# : Returns whether the file at the given path exists and is empty.
|
|
234
|
+
# * `'r+'`:
|
|
249
235
|
#
|
|
250
|
-
#
|
|
251
|
-
# : Returns the size (bytes) of the file at the given path.
|
|
236
|
+
# * File is not initially truncated:
|
|
252
237
|
#
|
|
253
|
-
#
|
|
254
|
-
#
|
|
255
|
-
#
|
|
238
|
+
# path = 't.tmp'
|
|
239
|
+
# File.write(path, text)
|
|
240
|
+
# f = File.new(path, 'r+')
|
|
241
|
+
# f.size == 0 # => false
|
|
256
242
|
#
|
|
257
|
-
#
|
|
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
|
-
#
|
|
250
|
+
# f.readline # => "First line\n"
|
|
251
|
+
# f.readline # => "Second line\n"
|
|
263
252
|
#
|
|
264
|
-
#
|
|
265
|
-
#
|
|
253
|
+
# f.rewind
|
|
254
|
+
# f.readline # => "First line\n"
|
|
266
255
|
#
|
|
267
|
-
#
|
|
268
|
-
#
|
|
256
|
+
# f.pos = 1
|
|
257
|
+
# f.readline # => "irst line\n"
|
|
269
258
|
#
|
|
270
|
-
#
|
|
271
|
-
#
|
|
259
|
+
# f.seek(1, :CUR)
|
|
260
|
+
# f.readline # => "econd line\n"
|
|
272
261
|
#
|
|
273
|
-
#
|
|
274
|
-
#
|
|
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
|
-
#
|
|
277
|
-
#
|
|
278
|
-
#
|
|
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
|
-
#
|
|
281
|
-
#
|
|
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
|
-
#
|
|
284
|
-
#
|
|
285
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
295
|
-
# : Truncates the file at the given file path to the given size.
|
|
564
|
+
# ### Integer Access Modes
|
|
296
565
|
#
|
|
297
|
-
#
|
|
298
|
-
#
|
|
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
|
-
#
|
|
301
|
-
#
|
|
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(
|
|
307
|
-
# - File.new(filename [, mode [, perm]] [, opt]) -> file
|
|
843
|
+
# - File.new(path, mode = 'r', perm = 0666, **opts) -> file
|
|
308
844
|
# -->
|
|
309
|
-
# Opens the file
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
319
|
-
#
|
|
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
|
-
#
|
|
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(
|
|
324
|
-
# f
|
|
325
|
-
# f = File.new(
|
|
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?(
|
|
942
|
+
# - File.blockdev?(filepath) -> true or false
|
|
391
943
|
# -->
|
|
392
|
-
# Returns `true` if
|
|
944
|
+
# Returns `true` if `filepath` points to a block device, `false` otherwise:
|
|
393
945
|
#
|
|
394
|
-
#
|
|
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?(
|
|
953
|
+
# - File.chardev?(filepath) -> true or false
|
|
401
954
|
# -->
|
|
402
|
-
# Returns `true` if
|
|
955
|
+
# Returns `true` if `filepath` points to a character device, `false` otherwise.
|
|
403
956
|
#
|
|
404
|
-
#
|
|
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?(
|
|
1021
|
+
# - File.directory?(path) -> true or false
|
|
468
1022
|
# -->
|
|
469
|
-
#
|
|
470
|
-
# directory,
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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(
|
|
1368
|
+
# - File.lstat(filepath) -> stat
|
|
810
1369
|
# -->
|
|
811
|
-
#
|
|
812
|
-
#
|
|
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(
|
|
815
|
-
# File.stat(
|
|
816
|
-
# File.lstat(
|
|
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(
|
|
857
|
-
# - File.open(
|
|
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
|
-
#
|
|
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
|
-
#
|
|
867
|
-
# `perm` parameter. See File.new for further discussion.
|
|
1419
|
+
# With no block given, returns the File object.
|
|
868
1420
|
#
|
|
869
|
-
#
|
|
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?(
|
|
1451
|
+
# - File.pipe?(filepath) -> true or false
|
|
899
1452
|
# -->
|
|
900
|
-
# Returns `true` if
|
|
1453
|
+
# Returns `true` if `filepath` points to a pipe, `false` otherwise:
|
|
901
1454
|
#
|
|
902
|
-
#
|
|
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?(
|
|
1579
|
+
# - File.socket?(filepath) -> true or false
|
|
1025
1580
|
# -->
|
|
1026
|
-
# Returns `true` if
|
|
1581
|
+
# Returns `true` if `filepath` points to a socket, `false` otherwise:
|
|
1027
1582
|
#
|
|
1028
|
-
#
|
|
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(
|
|
1602
|
+
# - File.stat(filepath) -> stat
|
|
1046
1603
|
# -->
|
|
1047
|
-
# Returns a File::Stat object for the
|
|
1604
|
+
# Returns a File::Stat object for the file at `filepath` (see File::Stat):
|
|
1048
1605
|
#
|
|
1049
|
-
# File.stat(
|
|
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?(
|
|
1634
|
+
# - File.symlink?(filepath) -> true or false
|
|
1078
1635
|
# -->
|
|
1079
|
-
# Returns `true` if
|
|
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
|
-
# -
|
|
1875
|
+
# - lstat -> stat
|
|
1315
1876
|
# -->
|
|
1316
|
-
#
|
|
1317
|
-
#
|
|
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(
|
|
1320
|
-
# File.
|
|
1321
|
-
# f
|
|
1322
|
-
# f.lstat.size
|
|
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 ->
|
|
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 ->
|
|
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?(
|
|
2197
|
+
# - File.directory?(path) -> true or false
|
|
1638
2198
|
# -->
|
|
1639
|
-
#
|
|
1640
|
-
# directory,
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
|
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 ->
|
|
2319
|
+
# - stat.mtime -> time
|
|
1755
2320
|
# -->
|
|
1756
2321
|
# Returns the modification time of *stat*.
|
|
1757
2322
|
#
|