steep 0.16.0 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +6 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep/project/file.rb +1 -1
  9. data/lib/steep/project/hover_content.rb +1 -1
  10. data/lib/steep/server/code_worker.rb +1 -1
  11. data/lib/steep/server/signature_worker.rb +4 -4
  12. data/lib/steep/type_construction.rb +10 -16
  13. data/lib/steep/type_inference/constant_env.rb +2 -10
  14. data/lib/steep/type_inference/context.rb +1 -0
  15. data/lib/steep/version.rb +1 -1
  16. data/steep.gemspec +1 -5
  17. metadata +17 -135
  18. data/exe/rbs +0 -3
  19. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  20. data/vendor/ruby-signature/.gitignore +0 -12
  21. data/vendor/ruby-signature/.rubocop.yml +0 -15
  22. data/vendor/ruby-signature/BSDL +0 -22
  23. data/vendor/ruby-signature/COPYING +0 -56
  24. data/vendor/ruby-signature/Gemfile +0 -6
  25. data/vendor/ruby-signature/README.md +0 -93
  26. data/vendor/ruby-signature/Rakefile +0 -142
  27. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
  28. data/vendor/ruby-signature/bin/console +0 -14
  29. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  30. data/vendor/ruby-signature/bin/setup +0 -10
  31. data/vendor/ruby-signature/bin/sort +0 -89
  32. data/vendor/ruby-signature/bin/test_runner.rb +0 -16
  33. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  34. data/vendor/ruby-signature/docs/sigs.md +0 -148
  35. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  36. data/vendor/ruby-signature/docs/syntax.md +0 -528
  37. data/vendor/ruby-signature/exe/rbs +0 -7
  38. data/vendor/ruby-signature/lib/rbs.rb +0 -64
  39. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
  40. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
  41. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
  42. data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
  43. data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
  44. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
  45. data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
  46. data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
  47. data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
  48. data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
  49. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
  50. data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
  51. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
  52. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
  53. data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
  54. data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
  55. data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
  56. data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
  57. data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
  58. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
  59. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
  60. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
  61. data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
  62. data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
  63. data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
  64. data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
  65. data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
  66. data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
  67. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
  68. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
  69. data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
  70. data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
  71. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
  72. data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
  73. data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
  74. data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
  75. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
  76. data/vendor/ruby-signature/rbs.gemspec +0 -46
  77. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
  78. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
  79. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
  80. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  81. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  82. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  83. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -45
  84. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  85. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  86. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  87. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  88. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  89. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  90. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
  91. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
  92. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  93. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  94. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  95. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  96. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
  97. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  98. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  99. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  100. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
  101. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  102. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  103. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
  104. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  105. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
  106. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  107. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
  108. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
  109. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
  110. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
  111. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
  112. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
  113. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  114. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  115. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  116. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
  117. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
  118. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
  119. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  120. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  121. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
  122. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
  123. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  124. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  125. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
  126. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
  127. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  128. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
  129. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
  130. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  131. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
  132. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
  133. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  134. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
  135. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  136. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
  137. data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
  138. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
  139. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
  140. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
  141. data/vendor/ruby-signature/stdlib/json/json.rbs +0 -335
  142. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
  143. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  144. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  145. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  146. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
  147. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,194 +0,0 @@
1
- # Descendants of class [Exception](Exception) are used
2
- # to communicate between
3
- # [Kernel\#raise](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-raise)
4
- # and `rescue` statements in `begin ... end` blocks.
5
- # [Exception](Exception) objects carry information
6
- # about the exception – its type (the exception’s class name), an optional
7
- # descriptive string, and optional traceback information.
8
- # [Exception](Exception) subclasses may add additional
9
- # information like
10
- # [NameError\#name](https://ruby-doc.org/core-2.6.3/NameError.html#method-i-name)
11
- # .
12
- #
13
- # Programs may make subclasses of
14
- # [Exception](Exception), typically of
15
- # [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html) or
16
- # [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html), to
17
- # provide custom classes and add additional information. See the subclass
18
- # list below for defaults for `raise` and `rescue` .
19
- #
20
- # When an exception has been raised but not yet handled (in `rescue`,
21
- # `ensure`, `at_exit` and `END` blocks) the global variable `$!` will
22
- # contain the current exception and `$@` contains the current exception’s
23
- # backtrace.
24
- #
25
- # It is recommended that a library should have one subclass of
26
- # [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html) or
27
- # [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html) and
28
- # have specific exception types inherit from it. This allows the user to
29
- # rescue a generic exception type to catch all exceptions the library may
30
- # raise even if future versions of the library add new exception
31
- # subclasses.
32
- #
33
- # For example:
34
- #
35
- # ```ruby
36
- # class MyLibrary
37
- # class Error < RuntimeError
38
- # end
39
- #
40
- # class WidgetError < Error
41
- # end
42
- #
43
- # class FrobError < Error
44
- # end
45
- #
46
- # end
47
- # ```
48
- #
49
- # To handle both WidgetError and FrobError the library user can rescue
50
- # MyLibrary::Error.
51
- #
52
- # The built-in subclasses of [Exception](Exception)
53
- # are:
54
- #
55
- # - [NoMemoryError](https://ruby-doc.org/core-2.6.3/NoMemoryError.html)
56
- #
57
- # - [ScriptError](https://ruby-doc.org/core-2.6.3/ScriptError.html)
58
- #
59
- # - [LoadError](https://ruby-doc.org/core-2.6.3/LoadError.html)
60
- #
61
- # - [NotImplementedError](https://ruby-doc.org/core-2.6.3/NotImplementedError.html)
62
- #
63
- # - [SyntaxError](https://ruby-doc.org/core-2.6.3/SyntaxError.html)
64
- #
65
- # - [SecurityError](https://ruby-doc.org/core-2.6.3/SecurityError.html)
66
- #
67
- # - [SignalException](https://ruby-doc.org/core-2.6.3/SignalException.html)
68
- #
69
- # - [Interrupt](https://ruby-doc.org/core-2.6.3/Interrupt.html)
70
- #
71
- # - [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html)
72
- # -- default for `rescue`
73
- #
74
- # - [ArgumentError](https://ruby-doc.org/core-2.6.3/ArgumentError.html)
75
- #
76
- # - [UncaughtThrowError](https://ruby-doc.org/core-2.6.3/UncaughtThrowError.html)
77
- #
78
- # - [EncodingError](https://ruby-doc.org/core-2.6.3/EncodingError.html)
79
- #
80
- # - [FiberError](https://ruby-doc.org/core-2.6.3/FiberError.html)
81
- #
82
- # - [IOError](https://ruby-doc.org/core-2.6.3/IOError.html)
83
- #
84
- # - [EOFError](https://ruby-doc.org/core-2.6.3/EOFError.html)
85
- #
86
- # - [IndexError](https://ruby-doc.org/core-2.6.3/IndexError.html)
87
- #
88
- # - [KeyError](https://ruby-doc.org/core-2.6.3/KeyError.html)
89
- #
90
- # - [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html)
91
- #
92
- # - [LocalJumpError](https://ruby-doc.org/core-2.6.3/LocalJumpError.html)
93
- #
94
- # - [NameError](https://ruby-doc.org/core-2.6.3/NameError.html)
95
- #
96
- # - [NoMethodError](https://ruby-doc.org/core-2.6.3/NoMethodError.html)
97
- #
98
- # - [RangeError](https://ruby-doc.org/core-2.6.3/RangeError.html)
99
- #
100
- # - [FloatDomainError](https://ruby-doc.org/core-2.6.3/FloatDomainError.html)
101
- #
102
- # - [RegexpError](https://ruby-doc.org/core-2.6.3/RegexpError.html)
103
- #
104
- # - [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
105
- # -- default for `raise`
106
- #
107
- # - [FrozenError](https://ruby-doc.org/core-2.6.3/FrozenError.html)
108
- #
109
- # - [SystemCallError](https://ruby-doc.org/core-2.6.3/SystemCallError.html)
110
- #
111
- # - Errno::\*
112
- #
113
- # - [ThreadError](https://ruby-doc.org/core-2.6.3/ThreadError.html)
114
- #
115
- # - [TypeError](https://ruby-doc.org/core-2.6.3/TypeError.html)
116
- #
117
- # - [ZeroDivisionError](https://ruby-doc.org/core-2.6.3/ZeroDivisionError.html)
118
- #
119
- # - [SystemExit](https://ruby-doc.org/core-2.6.3/SystemExit.html)
120
- #
121
- # - [SystemStackError](https://ruby-doc.org/core-2.6.3/SystemStackError.html)
122
- #
123
- # - fatal – impossible to rescue
124
- class Exception < Object
125
- def self.to_tty?: () -> bool
126
-
127
- def self.exception: (?String msg) -> Exception
128
-
129
- def ==: (untyped arg0) -> bool
130
-
131
- # Returns any backtrace associated with the exception. The backtrace is an
132
- # array of strings, each containing either “filename:lineNo: in \`method”‘
133
- # or “filename:lineNo.”
134
- #
135
- # ```ruby
136
- # def a
137
- # raise "boom"
138
- # end
139
- #
140
- # def b
141
- # a()
142
- # end
143
- #
144
- # begin
145
- # b()
146
- # rescue => detail
147
- # print detail.backtrace.join("\n")
148
- # end
149
- # ```
150
- #
151
- # *produces:*
152
- #
153
- # prog.rb:2:in `a'
154
- # prog.rb:6:in `b'
155
- # prog.rb:10
156
- def backtrace: () -> ::Array[String]?
157
-
158
- # Returns any backtrace associated with the exception. This method is
159
- # similar to
160
- # [\#backtrace](Exception.downloaded.ruby_doc#method-i-backtrace), but
161
- # the backtrace is an array of
162
- # [Thread::Backtrace::Location](https://ruby-doc.org/core-2.6.3/Thread/Backtrace/Location.html)
163
- # .
164
- #
165
- # Now, this method is not affected by
166
- # [\#set\_backtrace](Exception.downloaded.ruby_doc#method-i-set_backtrace)
167
- # .
168
- def backtrace_locations: () -> ::Array[Thread::Backtrace::Location]?
169
-
170
- # Returns the previous exception ($\!) at the time this exception was
171
- # raised. This is useful for wrapping exceptions and retaining the
172
- # original exception information.
173
- def cause: () -> Exception?
174
-
175
- def exception: () -> self
176
- | (String arg0) -> Exception
177
-
178
- def initialize: (?String arg0) -> void
179
-
180
- # Return this exception’s class name and message.
181
- def inspect: () -> String
182
-
183
- # Returns the result of invoking `exception.to_s` . Normally this returns
184
- # the exception’s message or name.
185
- def message: () -> String
186
-
187
- def set_backtrace: (String | ::Array[String] arg0) -> ::Array[String]
188
-
189
- # Returns exception’s message (or the name of the exception if no message
190
- # is set).
191
- def to_s: () -> String
192
-
193
- def full_message: (?highlight: bool, ?order: :top | :bottom) -> String
194
- end
@@ -1,40 +0,0 @@
1
- # The global value `false` is the only instance of class FalseClass and
2
- # represents a logically false value in boolean expressions. The class provides
3
- # operators allowing `false` to participate correctly in logical expressions.
4
- #
5
- class FalseClass
6
- public
7
-
8
- def !: () -> bool
9
-
10
- # And---Returns `false`. *obj* is always evaluated as it is the argument to a
11
- # method call---there is no short-circuit evaluation in this case.
12
- #
13
- def &: (untyped obj) -> bool
14
-
15
- # Case Equality -- For class Object, effectively the same as calling `#==`, but
16
- # typically overridden by descendants to provide meaningful semantics in `case`
17
- # statements.
18
- #
19
- def ===: (false) -> true
20
- | (untyped obj) -> bool
21
-
22
- # Exclusive Or---If *obj* is `nil` or `false`, returns `false`; otherwise,
23
- # returns `true`.
24
- #
25
- def ^: (nil) -> false
26
- | (false) -> false
27
- | (untyped obj) -> bool
28
-
29
- alias inspect to_s
30
-
31
- # The string representation of `false` is "false".
32
- #
33
- def to_s: () -> "false"
34
-
35
- # Or---Returns `false` if *obj* is `nil` or `false`; `true` otherwise.
36
- #
37
- def |: (nil) -> false
38
- | (false) -> false
39
- | (untyped obj) -> bool
40
- end
@@ -1,68 +0,0 @@
1
- # Fibers are primitives for implementing light weight cooperative
2
- # concurrency in Ruby. Basically they are a means of creating code blocks
3
- # that can be paused and resumed, much like threads. The main difference
4
- # is that they are never preempted and that the scheduling must be done by
5
- # the programmer and not the VM.
6
- #
7
- # As opposed to other stackless light weight concurrency models, each
8
- # fiber comes with a stack. This enables the fiber to be paused from
9
- # deeply nested function calls within the fiber block. See the ruby(1)
10
- # manpage to configure the size of the fiber stack(s).
11
- #
12
- # When a fiber is created it will not run automatically. Rather it must be
13
- # explicitly asked to run using the `Fiber#resume` method. The code
14
- # running inside the fiber can give up control by calling `Fiber.yield` in
15
- # which case it yields control back to caller (the caller of the
16
- # `Fiber#resume` ).
17
- #
18
- # Upon yielding or termination the [Fiber](Fiber)
19
- # returns the value of the last executed expression
20
- #
21
- # For instance:
22
- #
23
- # ```ruby
24
- # fiber = Fiber.new do
25
- # Fiber.yield 1
26
- # 2
27
- # end
28
- #
29
- # puts fiber.resume
30
- # puts fiber.resume
31
- # puts fiber.resume
32
- # ```
33
- #
34
- # *produces*
35
- #
36
- # 1
37
- # 2
38
- # FiberError: dead fiber called
39
- #
40
- # The `Fiber#resume` method accepts an arbitrary number of parameters, if
41
- # it is the first call to `resume` then they will be passed as block
42
- # arguments. Otherwise they will be the return value of the call to
43
- # `Fiber.yield`
44
- #
45
- # Example:
46
- #
47
- # ```ruby
48
- # fiber = Fiber.new do |first|
49
- # second = Fiber.yield first + 2
50
- # end
51
- #
52
- # puts fiber.resume 10
53
- # puts fiber.resume 14
54
- # puts fiber.resume 18
55
- # ```
56
- #
57
- # *produces*
58
- #
59
- # 12
60
- # 14
61
- # FiberError: dead fiber called
62
- class Fiber < Object
63
- def self.yield: (*untyped args) -> untyped
64
-
65
- def initialize: () { () -> void } -> Fiber
66
-
67
- def resume: (*untyped args) -> untyped
68
- end
@@ -1,12 +0,0 @@
1
- # Raised when an invalid operation is attempted on a
2
- # [Fiber](https://ruby-doc.org/core-2.6.3/Fiber.html), in particular when
3
- # attempting to call/resume a dead fiber, attempting to yield from the
4
- # root fiber, or calling a fiber across threads.
5
- #
6
- # ```ruby
7
- # fiber = Fiber.new{}
8
- # fiber.resume #=> nil
9
- # fiber.resume #=> FiberError: dead fiber called
10
- # ```
11
- class FiberError < StandardError
12
- end
@@ -1,1076 +0,0 @@
1
- # A File is an abstraction of any file object accessible by the program and is
2
- # closely associated with class IO. File includes the methods of module
3
- # FileTest as class methods, allowing you to write (for example)
4
- # `File.exist?("foo")`.
5
- #
6
- # In the description of File methods, *permission bits* are a platform-specific
7
- # set of bits that indicate permissions of a file. On Unix-based systems,
8
- # permissions are viewed as a set of three octets, for the owner, the group, and
9
- # the rest of the world. For each of these entities, permissions may be set to
10
- # read, write, or execute the file:
11
- #
12
- # The permission bits `0644` (in octal) would thus be interpreted as read/write
13
- # for owner, and read-only for group and other. Higher-order bits may also be
14
- # used to indicate the type of file (plain, directory, pipe, socket, and so on)
15
- # and various other special features. If the permissions are for a directory,
16
- # the meaning of the execute bit changes; when set the directory can be
17
- # searched.
18
- #
19
- # On non-Posix operating systems, there may be only the ability to make a file
20
- # read-only or read-write. In this case, the remaining permission bits will be
21
- # synthesized to resemble typical values. For instance, on Windows NT the
22
- # default permission bits are `0644`, which means read/write for owner,
23
- # read-only for all others. The only change that can be made is to make the file
24
- # read-only, which is reported as `0444`.
25
- #
26
- # Various constants for the methods in File can be found in File::Constants.
27
- #
28
- class File < IO
29
- # Opens the file named by `filename` according to the given `mode` and returns a
30
- # new File object.
31
- #
32
- # See IO.new for a description of `mode` and `opt`.
33
- #
34
- # If a file is being created, permission bits may be given in `perm`. These
35
- # mode and permission bits are platform dependent; on Unix systems, see open(2)
36
- # and chmod(2) man pages for details.
37
- #
38
- # The new File object is buffered mode (or non-sync mode), unless `filename` is
39
- # a tty. See IO#flush, IO#fsync, IO#fdatasync, and IO#sync= about sync mode.
40
- #
41
- # ### Examples
42
- #
43
- # f = File.new("testfile", "r")
44
- # f = File.new("newfile", "w+")
45
- # f = File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)
46
- #
47
- def initialize: (string | _ToPath | int file_name, ?(string | int) mode, ?int perm) -> File
48
-
49
- # Converts a pathname to an absolute pathname. Relative paths are referenced
50
- # from the current working directory of the process unless *dir_string* is
51
- # given, in which case it will be used as the starting point. If the given
52
- # pathname starts with a ```~`'' it is NOT expanded, it is treated as a normal
53
- # directory name.
54
- #
55
- # File.absolute_path("~oracle/bin") #=> "<relative_path>/~oracle/bin"
56
- #
57
- def self.absolute_path: (string | _ToPath file_name, ?(string | _ToPath) dir_string) -> String
58
-
59
- # Returns `true` if `file_name` is an absolute path, and `false` otherwise.
60
- #
61
- # File.absolute_path?("c:/foo") #=> false (on Linux), true (on Windows)
62
- #
63
- # # arglists 💪👽🚨 << Delete this section
64
- # File.absolute_path?(file_name) -> true or false
65
- #
66
- def self.absolute_path?: (string | _ToPath file_name) -> bool
67
-
68
- # Returns the last access time for the named file as a Time object.
69
- #
70
- # *file_name* can be an IO object.
71
- #
72
- # File.atime("testfile") #=> Wed Apr 09 08:51:48 CDT 2003
73
- #
74
- def self.atime: (string | _ToPath | IO file_name) -> Time
75
-
76
- # Returns the last component of the filename given in *file_name* (after first
77
- # stripping trailing separators), which can be formed using both File::SEPARATOR
78
- # and File::ALT_SEPARATOR as the separator when File::ALT_SEPARATOR is not
79
- # `nil`. If *suffix* is given and present at the end of *file_name*, it is
80
- # removed. If *suffix* is ".*", any extension will be removed.
81
- #
82
- # File.basename("/home/gumby/work/ruby.rb") #=> "ruby.rb"
83
- # File.basename("/home/gumby/work/ruby.rb", ".rb") #=> "ruby"
84
- # File.basename("/home/gumby/work/ruby.rb", ".*") #=> "ruby"
85
- #
86
- def self.basename: (string | _ToPath file_name, ?string suffix) -> String
87
-
88
- def self.birthtime: (string | _ToPath | IO file_name) -> Time
89
-
90
- # Returns `true` if the named file is a block device.
91
- #
92
- # *file_name* can be an IO object.
93
- #
94
- def self.blockdev?: (string | _ToPath | IO file_name) -> bool
95
-
96
- # Returns `true` if the named file is a character device.
97
- #
98
- # *file_name* can be an IO object.
99
- #
100
- def self.chardev?: (string | _ToPath | IO file_name) -> bool
101
-
102
- # Changes permission bits on the named file(s) to the bit pattern represented by
103
- # *mode_int*. Actual effects are operating system dependent (see the beginning
104
- # of this section). On Unix systems, see `chmod(2)` for details. Returns the
105
- # number of files processed.
106
- #
107
- # File.chmod(0644, "testfile", "out") #=> 2
108
- #
109
- def self.chmod: (int mode, *(string | _ToPath) file_name) -> Integer
110
-
111
- # Changes the owner and group of the named file(s) to the given numeric owner
112
- # and group id's. Only a process with superuser privileges may change the owner
113
- # of a file. The current owner of a file may change the file's group to any
114
- # group to which the owner belongs. A `nil` or -1 owner or group id is ignored.
115
- # Returns the number of files processed.
116
- #
117
- # File.chown(nil, 100, "testfile")
118
- #
119
- def self.chown: (int? owner, int? group, *(string | _ToPath) file_name) -> Integer
120
-
121
- # Returns the change time for the named file (the time at which directory
122
- # information about the file was changed, not the file itself).
123
- #
124
- # *file_name* can be an IO object.
125
- #
126
- # Note that on Windows (NTFS), returns creation time (birth time).
127
- #
128
- # File.ctime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
129
- #
130
- def self.ctime: (string | _ToPath | IO file_name) -> Time
131
-
132
- # Deletes the named files, returning the number of names passed as arguments.
133
- # Raises an exception on any error. Since the underlying implementation relies
134
- # on the `unlink(2)` system call, the type of exception raised depends on its
135
- # error type (see https://linux.die.net/man/2/unlink) and has the form of e.g.
136
- # Errno::ENOENT.
137
- #
138
- # See also Dir::rmdir.
139
- #
140
- alias self.delete self.unlink
141
-
142
- # Returns `true` if the named file is a directory, or a symlink that points at a
143
- # directory, and `false` otherwise.
144
- #
145
- # *file_name* can be an IO object.
146
- #
147
- # File.directory?(".")
148
- #
149
- def self.directory?: (string | _ToPath | IO path) -> bool
150
-
151
- # Returns all components of the filename given in *file_name* except the last
152
- # one (after first stripping trailing separators). The filename can be formed
153
- # using both File::SEPARATOR and File::ALT_SEPARATOR as the separator when
154
- # File::ALT_SEPARATOR is not `nil`.
155
- #
156
- # File.dirname("/home/gumby/work/ruby.rb") #=> "/home/gumby/work"
157
- #
158
- def self.dirname: (string | _ToPath file_name) -> String
159
-
160
- # Returns `true` if the named file exists and has a zero size.
161
- #
162
- # *file_name* can be an IO object.
163
- #
164
- alias self.empty? self.zero?
165
-
166
- # Returns `true` if the named file is executable by the effective user and group
167
- # id of this process. See eaccess(3).
168
- #
169
- # Windows does not support execute permissions separately from read permissions.
170
- # On Windows, a file is only considered executable if it ends in .bat, .cmd,
171
- # .com, or .exe.
172
- #
173
- # Note that some OS-level security features may cause this to return true even
174
- # though the file is not executable by the effective user/group.
175
- #
176
- def self.executable?: (string | _ToPath file_name) -> bool
177
-
178
- # Returns `true` if the named file is executable by the real user and group id
179
- # of this process. See access(3).
180
- #
181
- # Windows does not support execute permissions separately from read permissions.
182
- # On Windows, a file is only considered executable if it ends in .bat, .cmd,
183
- # .com, or .exe.
184
- #
185
- # Note that some OS-level security features may cause this to return true even
186
- # though the file is not executable by the real user/group.
187
- #
188
- def self.executable_real?: (string | _ToPath file_name) -> bool
189
-
190
- # Return `true` if the named file exists.
191
- #
192
- # *file_name* can be an IO object.
193
- #
194
- # "file exists" means that stat() or fstat() system call is successful.
195
- #
196
- def self.exist?: (string | _ToPath | IO file_name) -> bool
197
-
198
- # Deprecated method. Don't use.
199
- #
200
- alias self.exists? self.exist?
201
-
202
- # Converts a pathname to an absolute pathname. Relative paths are referenced
203
- # from the current working directory of the process unless `dir_string` is
204
- # given, in which case it will be used as the starting point. The given pathname
205
- # may start with a ```~`'', which expands to the process owner's home directory
206
- # (the environment variable `HOME` must be set correctly). ```~`*user*'' expands
207
- # to the named user's home directory.
208
- #
209
- # File.expand_path("~oracle/bin") #=> "/home/oracle/bin"
210
- #
211
- # A simple example of using `dir_string` is as follows.
212
- # File.expand_path("ruby", "/usr/bin") #=> "/usr/bin/ruby"
213
- #
214
- # A more complex example which also resolves parent directory is as follows.
215
- # Suppose we are in bin/mygem and want the absolute path of lib/mygem.rb.
216
- #
217
- # File.expand_path("../../lib/mygem.rb", __FILE__)
218
- # #=> ".../path/to/project/lib/mygem.rb"
219
- #
220
- # So first it resolves the parent of __FILE__, that is bin/, then go to the
221
- # parent, the root of the project and appends `lib/mygem.rb`.
222
- #
223
- def self.expand_path: (string | _ToPath file_name, ?(string | _ToPath) dir_string) -> String
224
-
225
- # Returns the extension (the portion of file name in `path` starting from the
226
- # last period).
227
- #
228
- # If `path` is a dotfile, or starts with a period, then the starting dot is not
229
- # dealt with the start of the extension.
230
- #
231
- # An empty string will also be returned when the period is the last character in
232
- # `path`.
233
- #
234
- # On Windows, trailing dots are truncated.
235
- #
236
- # File.extname("test.rb") #=> ".rb"
237
- # File.extname("a/b/d/test.rb") #=> ".rb"
238
- # File.extname(".a/b/d/test.rb") #=> ".rb"
239
- # File.extname("foo.") #=> "" on Windows
240
- # File.extname("foo.") #=> "." on non-Windows
241
- # File.extname("test") #=> ""
242
- # File.extname(".profile") #=> ""
243
- # File.extname(".profile.sh") #=> ".sh"
244
- #
245
- def self.extname: (string | _ToPath path) -> String
246
-
247
- # Returns `true` if the named `file` exists and is a regular file.
248
- #
249
- # `file` can be an IO object.
250
- #
251
- # If the `file` argument is a symbolic link, it will resolve the symbolic link
252
- # and use the file referenced by the link.
253
- #
254
- def self.file?: (string | _ToPath | IO file) -> bool
255
-
256
- # Returns true if `path` matches against `pattern`. The pattern is not a
257
- # regular expression; instead it follows rules similar to shell filename
258
- # globbing. It may contain the following metacharacters:
259
- #
260
- # `*`
261
- # : Matches any file. Can be restricted by other values in the glob.
262
- # Equivalent to `/ .* /x` in regexp.
263
- #
264
- # `*`
265
- # : Matches all files regular files
266
- # `c*`
267
- # : Matches all files beginning with `c`
268
- # `*c`
269
- # : Matches all files ending with `c`
270
- # `*c*`
271
- # : Matches all files that have `c` in them (including at the beginning or
272
- # end).
273
- #
274
- #
275
- # To match hidden files (that start with a `.` set the File::FNM_DOTMATCH
276
- # flag.
277
- #
278
- # `**`
279
- # : Matches directories recursively or files expansively.
280
- #
281
- # `?`
282
- # : Matches any one character. Equivalent to `/.{1}/` in regexp.
283
- #
284
- # `[set]`
285
- # : Matches any one character in `set`. Behaves exactly like character sets
286
- # in Regexp, including set negation (`[^a-z]`).
287
- #
288
- # ` \ `
289
- # : Escapes the next metacharacter.
290
- #
291
- # `{a,b}`
292
- # : Matches pattern a and pattern b if File::FNM_EXTGLOB flag is enabled.
293
- # Behaves like a Regexp union (`(?:a|b)`).
294
- #
295
- #
296
- # `flags` is a bitwise OR of the `FNM_XXX` constants. The same glob pattern and
297
- # flags are used by Dir::glob.
298
- #
299
- # Examples:
300
- #
301
- # File.fnmatch('cat', 'cat') #=> true # match entire string
302
- # File.fnmatch('cat', 'category') #=> false # only match partial string
303
- #
304
- # File.fnmatch('c{at,ub}s', 'cats') #=> false # { } isn't supported by default
305
- # File.fnmatch('c{at,ub}s', 'cats', File::FNM_EXTGLOB) #=> true # { } is supported on FNM_EXTGLOB
306
- #
307
- # File.fnmatch('c?t', 'cat') #=> true # '?' match only 1 character
308
- # File.fnmatch('c??t', 'cat') #=> false # ditto
309
- # File.fnmatch('c*', 'cats') #=> true # '*' match 0 or more characters
310
- # File.fnmatch('c*t', 'c/a/b/t') #=> true # ditto
311
- # File.fnmatch('ca[a-z]', 'cat') #=> true # inclusive bracket expression
312
- # File.fnmatch('ca[^t]', 'cat') #=> false # exclusive bracket expression ('^' or '!')
313
- #
314
- # File.fnmatch('cat', 'CAT') #=> false # case sensitive
315
- # File.fnmatch('cat', 'CAT', File::FNM_CASEFOLD) #=> true # case insensitive
316
- # File.fnmatch('cat', 'CAT', File::FNM_SYSCASE) #=> true or false # depends on the system default
317
- #
318
- # File.fnmatch('?', '/', File::FNM_PATHNAME) #=> false # wildcard doesn't match '/' on FNM_PATHNAME
319
- # File.fnmatch('*', '/', File::FNM_PATHNAME) #=> false # ditto
320
- # File.fnmatch('[/]', '/', File::FNM_PATHNAME) #=> false # ditto
321
- #
322
- # File.fnmatch('\?', '?') #=> true # escaped wildcard becomes ordinary
323
- # File.fnmatch('\a', 'a') #=> true # escaped ordinary remains ordinary
324
- # File.fnmatch('\a', '\a', File::FNM_NOESCAPE) #=> true # FNM_NOESCAPE makes '\' ordinary
325
- # File.fnmatch('[\?]', '?') #=> true # can escape inside bracket expression
326
- #
327
- # File.fnmatch('*', '.profile') #=> false # wildcard doesn't match leading
328
- # File.fnmatch('*', '.profile', File::FNM_DOTMATCH) #=> true # period by default.
329
- # File.fnmatch('.*', '.profile') #=> true
330
- #
331
- # rbfiles = '**' '/' '*.rb' # you don't have to do like this. just write in single string.
332
- # File.fnmatch(rbfiles, 'main.rb') #=> false
333
- # File.fnmatch(rbfiles, './main.rb') #=> false
334
- # File.fnmatch(rbfiles, 'lib/song.rb') #=> true
335
- # File.fnmatch('**.rb', 'main.rb') #=> true
336
- # File.fnmatch('**.rb', './main.rb') #=> false
337
- # File.fnmatch('**.rb', 'lib/song.rb') #=> true
338
- # File.fnmatch('*', 'dave/.profile') #=> true
339
- #
340
- # pattern = '*' '/' '*'
341
- # File.fnmatch(pattern, 'dave/.profile', File::FNM_PATHNAME) #=> false
342
- # File.fnmatch(pattern, 'dave/.profile', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
343
- #
344
- # pattern = '**' '/' 'foo'
345
- # File.fnmatch(pattern, 'a/b/c/foo', File::FNM_PATHNAME) #=> true
346
- # File.fnmatch(pattern, '/a/b/c/foo', File::FNM_PATHNAME) #=> true
347
- # File.fnmatch(pattern, 'c:/a/b/c/foo', File::FNM_PATHNAME) #=> true
348
- # File.fnmatch(pattern, 'a/.b/c/foo', File::FNM_PATHNAME) #=> false
349
- # File.fnmatch(pattern, 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
350
- #
351
- def self.fnmatch: (string pattern, string | _ToPath path, ?int flags) -> bool
352
-
353
- # Returns true if `path` matches against `pattern`. The pattern is not a
354
- # regular expression; instead it follows rules similar to shell filename
355
- # globbing. It may contain the following metacharacters:
356
- #
357
- # `*`
358
- # : Matches any file. Can be restricted by other values in the glob.
359
- # Equivalent to `/ .* /x` in regexp.
360
- #
361
- # `*`
362
- # : Matches all files regular files
363
- # `c*`
364
- # : Matches all files beginning with `c`
365
- # `*c`
366
- # : Matches all files ending with `c`
367
- # `*c*`
368
- # : Matches all files that have `c` in them (including at the beginning or
369
- # end).
370
- #
371
- #
372
- # To match hidden files (that start with a `.` set the File::FNM_DOTMATCH
373
- # flag.
374
- #
375
- # `**`
376
- # : Matches directories recursively or files expansively.
377
- #
378
- # `?`
379
- # : Matches any one character. Equivalent to `/.{1}/` in regexp.
380
- #
381
- # `[set]`
382
- # : Matches any one character in `set`. Behaves exactly like character sets
383
- # in Regexp, including set negation (`[^a-z]`).
384
- #
385
- # ` \ `
386
- # : Escapes the next metacharacter.
387
- #
388
- # `{a,b}`
389
- # : Matches pattern a and pattern b if File::FNM_EXTGLOB flag is enabled.
390
- # Behaves like a Regexp union (`(?:a|b)`).
391
- #
392
- #
393
- # `flags` is a bitwise OR of the `FNM_XXX` constants. The same glob pattern and
394
- # flags are used by Dir::glob.
395
- #
396
- # Examples:
397
- #
398
- # File.fnmatch('cat', 'cat') #=> true # match entire string
399
- # File.fnmatch('cat', 'category') #=> false # only match partial string
400
- #
401
- # File.fnmatch('c{at,ub}s', 'cats') #=> false # { } isn't supported by default
402
- # File.fnmatch('c{at,ub}s', 'cats', File::FNM_EXTGLOB) #=> true # { } is supported on FNM_EXTGLOB
403
- #
404
- # File.fnmatch('c?t', 'cat') #=> true # '?' match only 1 character
405
- # File.fnmatch('c??t', 'cat') #=> false # ditto
406
- # File.fnmatch('c*', 'cats') #=> true # '*' match 0 or more characters
407
- # File.fnmatch('c*t', 'c/a/b/t') #=> true # ditto
408
- # File.fnmatch('ca[a-z]', 'cat') #=> true # inclusive bracket expression
409
- # File.fnmatch('ca[^t]', 'cat') #=> false # exclusive bracket expression ('^' or '!')
410
- #
411
- # File.fnmatch('cat', 'CAT') #=> false # case sensitive
412
- # File.fnmatch('cat', 'CAT', File::FNM_CASEFOLD) #=> true # case insensitive
413
- # File.fnmatch('cat', 'CAT', File::FNM_SYSCASE) #=> true or false # depends on the system default
414
- #
415
- # File.fnmatch('?', '/', File::FNM_PATHNAME) #=> false # wildcard doesn't match '/' on FNM_PATHNAME
416
- # File.fnmatch('*', '/', File::FNM_PATHNAME) #=> false # ditto
417
- # File.fnmatch('[/]', '/', File::FNM_PATHNAME) #=> false # ditto
418
- #
419
- # File.fnmatch('\?', '?') #=> true # escaped wildcard becomes ordinary
420
- # File.fnmatch('\a', 'a') #=> true # escaped ordinary remains ordinary
421
- # File.fnmatch('\a', '\a', File::FNM_NOESCAPE) #=> true # FNM_NOESCAPE makes '\' ordinary
422
- # File.fnmatch('[\?]', '?') #=> true # can escape inside bracket expression
423
- #
424
- # File.fnmatch('*', '.profile') #=> false # wildcard doesn't match leading
425
- # File.fnmatch('*', '.profile', File::FNM_DOTMATCH) #=> true # period by default.
426
- # File.fnmatch('.*', '.profile') #=> true
427
- #
428
- # rbfiles = '**' '/' '*.rb' # you don't have to do like this. just write in single string.
429
- # File.fnmatch(rbfiles, 'main.rb') #=> false
430
- # File.fnmatch(rbfiles, './main.rb') #=> false
431
- # File.fnmatch(rbfiles, 'lib/song.rb') #=> true
432
- # File.fnmatch('**.rb', 'main.rb') #=> true
433
- # File.fnmatch('**.rb', './main.rb') #=> false
434
- # File.fnmatch('**.rb', 'lib/song.rb') #=> true
435
- # File.fnmatch('*', 'dave/.profile') #=> true
436
- #
437
- # pattern = '*' '/' '*'
438
- # File.fnmatch(pattern, 'dave/.profile', File::FNM_PATHNAME) #=> false
439
- # File.fnmatch(pattern, 'dave/.profile', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
440
- #
441
- # pattern = '**' '/' 'foo'
442
- # File.fnmatch(pattern, 'a/b/c/foo', File::FNM_PATHNAME) #=> true
443
- # File.fnmatch(pattern, '/a/b/c/foo', File::FNM_PATHNAME) #=> true
444
- # File.fnmatch(pattern, 'c:/a/b/c/foo', File::FNM_PATHNAME) #=> true
445
- # File.fnmatch(pattern, 'a/.b/c/foo', File::FNM_PATHNAME) #=> false
446
- # File.fnmatch(pattern, 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
447
- #
448
- alias self.fnmatch? self.fnmatch
449
-
450
- # Identifies the type of the named file; the return string is one of ```file`'',
451
- # ```directory`'', ```characterSpecial`'', ```blockSpecial`'', ```fifo`'',
452
- # ```link`'', ```socket`'', or ```unknown`''.
453
- #
454
- # File.ftype("testfile") #=> "file"
455
- # File.ftype("/dev/tty") #=> "characterSpecial"
456
- # File.ftype("/tmp/.X11-unix/X0") #=> "socket"
457
- #
458
- def self.ftype: (string | _ToPath file_name) -> String
459
-
460
- # Returns `true` if the named file exists and the effective group id of the
461
- # calling process is the owner of the file. Returns `false` on Windows.
462
- #
463
- # *file_name* can be an IO object.
464
- #
465
- def self.grpowned?: (string | _ToPath | IO file_name) -> bool
466
-
467
- # Returns `true` if the named files are identical.
468
- #
469
- # *file_1* and *file_2* can be an IO object.
470
- #
471
- # open("a", "w") {}
472
- # p File.identical?("a", "a") #=> true
473
- # p File.identical?("a", "./a") #=> true
474
- # File.link("a", "b")
475
- # p File.identical?("a", "b") #=> true
476
- # File.symlink("a", "c")
477
- # p File.identical?("a", "c") #=> true
478
- # open("d", "w") {}
479
- # p File.identical?("a", "d") #=> false
480
- #
481
- def self.identical?: (string | _ToPath | IO file_1, string | _ToPath | IO file_2) -> bool
482
-
483
- # Returns a new string formed by joining the strings using `"/"`.
484
- #
485
- # File.join("usr", "mail", "gumby") #=> "usr/mail/gumby"
486
- #
487
- def self.join: (*string) -> String
488
-
489
- # Equivalent to File::chmod, but does not follow symbolic links (so it will
490
- # change the permissions associated with the link, not the file referenced by
491
- # the link). Often not available.
492
- #
493
- def self.lchmod: (int mode, *(string | _ToPath) file_name) -> Integer
494
-
495
- # Equivalent to File::chown, but does not follow symbolic links (so it will
496
- # change the owner associated with the link, not the file referenced by the
497
- # link). Often not available. Returns number of files in the argument list.
498
- #
499
- def self.lchown: (int? owner, int? group, *(string | _ToPath) file_name) -> Integer
500
-
501
- # Creates a new name for an existing file using a hard link. Will not overwrite
502
- # *new_name* if it already exists (raising a subclass of SystemCallError). Not
503
- # available on all platforms.
504
- #
505
- # File.link("testfile", ".testfile") #=> 0
506
- # IO.readlines(".testfile")[0] #=> "This is line one\n"
507
- #
508
- def self.link: (string | _ToPath old_name, string | _ToPath new_name) -> 0
509
-
510
- # Same as File::stat, but does not follow the last symbolic link. Instead,
511
- # reports on the link itself.
512
- #
513
- # File.symlink("testfile", "link2test") #=> 0
514
- # File.stat("testfile").size #=> 66
515
- # File.lstat("link2test").size #=> 8
516
- # File.stat("link2test").size #=> 66
517
- #
518
- def self.lstat: (string | _ToPath file_name) -> File::Stat
519
-
520
- # Sets the access and modification times of each named file to the first two
521
- # arguments. If a file is a symlink, this method acts upon the link itself as
522
- # opposed to its referent; for the inverse behavior, see File.utime. Returns the
523
- # number of file names in the argument list.
524
- #
525
- def self.lutime: ((Time | Numeric) atime, (Time | Numeric) mtime, *(string | _ToPath) file_name) -> Integer
526
-
527
- # Creates a FIFO special file with name *file_name*. *mode* specifies the
528
- # FIFO's permissions. It is modified by the process's umask in the usual way:
529
- # the permissions of the created file are (mode & ~umask).
530
- #
531
- def self.mkfifo: ((string | _ToPath) file_name, ?int mode) -> 0
532
-
533
- # Returns the modification time for the named file as a Time object.
534
- #
535
- # *file_name* can be an IO object.
536
- #
537
- # File.mtime("testfile") #=> Tue Apr 08 12:58:04 CDT 2003
538
- #
539
- def self.mtime: (string | _ToPath | IO file_name) -> Time
540
-
541
- # Returns `true` if the named file exists and the effective used id of the
542
- # calling process is the owner of the file.
543
- #
544
- # *file_name* can be an IO object.
545
- #
546
- def self.owned?: (string | _ToPath | IO file_name) -> bool
547
-
548
- # Returns the string representation of the path
549
- #
550
- # File.path("/dev/null") #=> "/dev/null"
551
- # File.path(Pathname.new("/tmp")) #=> "/tmp"
552
- #
553
- def self.path: (string | _ToPath path) -> String
554
-
555
- # Returns `true` if the named file is a pipe.
556
- #
557
- # *file_name* can be an IO object.
558
- #
559
- def self.pipe?: (string | _ToPath | IO file_name) -> bool
560
-
561
- # Returns `true` if the named file is readable by the effective user and group
562
- # id of this process. See eaccess(3).
563
- #
564
- # Note that some OS-level security features may cause this to return true even
565
- # though the file is not readable by the effective user/group.
566
- #
567
- def self.readable?: (string | _ToPath file_name) -> bool
568
-
569
- # Returns `true` if the named file is readable by the real user and group id of
570
- # this process. See access(3).
571
- #
572
- # Note that some OS-level security features may cause this to return true even
573
- # though the file is not readable by the real user/group.
574
- #
575
- def self.readable_real?: (string | _ToPath file_name) -> bool
576
-
577
- # Returns the name of the file referenced by the given link. Not available on
578
- # all platforms.
579
- #
580
- # File.symlink("testfile", "link2test") #=> 0
581
- # File.readlink("link2test") #=> "testfile"
582
- #
583
- def self.readlink: (string | _ToPath link_name) -> String
584
-
585
- # Returns the real (absolute) pathname of *pathname* in the actual filesystem.
586
- # The real pathname doesn't contain symlinks or useless dots.
587
- #
588
- # If *dir_string* is given, it is used as a base directory for interpreting
589
- # relative pathname instead of the current directory.
590
- #
591
- # The last component of the real pathname can be nonexistent.
592
- #
593
- def self.realdirpath: (string | _ToPath pathname, ?(string | _ToPath) dir_string) -> String
594
-
595
- # Returns the real (absolute) pathname of *pathname* in the actual filesystem
596
- # not containing symlinks or useless dots.
597
- #
598
- # If *dir_string* is given, it is used as a base directory for interpreting
599
- # relative pathname instead of the current directory.
600
- #
601
- # All components of the pathname must exist when this method is called.
602
- #
603
- def self.realpath: (string | _ToPath pathname, ?(string | _ToPath) dir_string) -> String
604
-
605
- # Renames the given file to the new name. Raises a SystemCallError if the file
606
- # cannot be renamed.
607
- #
608
- # File.rename("afile", "afile.bak") #=> 0
609
- #
610
- def self.rename: (string | _ToPath old_name, string | _ToPath new_name) -> 0
611
-
612
- # Returns `true` if the named file has the setgid bit set.
613
- #
614
- # *file_name* can be an IO object.
615
- #
616
- def self.setgid?: (string | _ToPath | IO file_name) -> bool
617
-
618
- # Returns `true` if the named file has the setuid bit set.
619
- #
620
- # *file_name* can be an IO object.
621
- #
622
- def self.setuid?: (string | _ToPath | IO file_name) -> bool
623
-
624
- # Returns the size of `file_name`.
625
- #
626
- # *file_name* can be an IO object.
627
- #
628
- def self.size: (string | _ToPath | IO file_name) -> Integer
629
-
630
- # Returns `nil` if `file_name` doesn't exist or has zero size, the size of the
631
- # file otherwise.
632
- #
633
- # *file_name* can be an IO object.
634
- #
635
- def self.size?: (string | _ToPath | IO file_name) -> Integer?
636
-
637
- # Returns `true` if the named file is a socket.
638
- #
639
- # *file_name* can be an IO object.
640
- #
641
- def self.socket?: (string | _ToPath | IO file_name) -> bool
642
-
643
- # Splits the given string into a directory and a file component and returns them
644
- # in a two-element array. See also File::dirname and File::basename.
645
- #
646
- # File.split("/home/gumby/.profile") #=> ["/home/gumby", ".profile"]
647
- #
648
- def self.split: (string | _ToPath file_name) -> [String, String]
649
-
650
- # Returns a File::Stat object for the named file (see File::Stat).
651
- #
652
- # File.stat("testfile").mtime #=> Tue Apr 08 12:58:04 CDT 2003
653
- #
654
- def self.stat: (string | _ToPath file_name) -> File::Stat
655
-
656
- # Returns `true` if the named file has the sticky bit set.
657
- #
658
- # *file_name* can be an IO object.
659
- #
660
- def self.sticky?: (string | _ToPath | IO file_name) -> bool
661
-
662
- # Creates a symbolic link called *new_name* for the existing file *old_name*.
663
- # Raises a NotImplemented exception on platforms that do not support symbolic
664
- # links.
665
- #
666
- # File.symlink("testfile", "link2test") #=> 0
667
- #
668
- def self.symlink: (string | _ToPath old_name, string | _ToPath new_name) -> 0
669
-
670
- # Returns `true` if the named file is a symbolic link.
671
- #
672
- def self.symlink?: (string | _ToPath file_name) -> bool
673
-
674
- # Truncates the file *file_name* to be at most *integer* bytes long. Not
675
- # available on all platforms.
676
- #
677
- # f = File.new("out", "w")
678
- # f.write("1234567890") #=> 10
679
- # f.close #=> nil
680
- # File.truncate("out", 5) #=> 0
681
- # File.size("out") #=> 5
682
- #
683
- def self.truncate: (string | _ToPath file_name, int length) -> 0
684
-
685
- # Returns the current umask value for this process. If the optional argument is
686
- # given, set the umask to that value and return the previous value. Umask values
687
- # are *subtracted* from the default permissions, so a umask of `0222` would make
688
- # a file read-only for everyone.
689
- #
690
- # File.umask(0006) #=> 18
691
- # File.umask #=> 6
692
- #
693
- def self.umask: (?int umask) -> Integer
694
-
695
- # Deletes the named files, returning the number of names passed as arguments.
696
- # Raises an exception on any error. Since the underlying implementation relies
697
- # on the `unlink(2)` system call, the type of exception raised depends on its
698
- # error type (see https://linux.die.net/man/2/unlink) and has the form of e.g.
699
- # Errno::ENOENT.
700
- #
701
- # See also Dir::rmdir.
702
- #
703
- def self.unlink: (*(string | _ToPath) file_name) -> Integer
704
-
705
- # Sets the access and modification times of each named file to the first two
706
- # arguments. If a file is a symlink, this method acts upon its referent rather
707
- # than the link itself; for the inverse behavior see File.lutime. Returns the
708
- # number of file names in the argument list.
709
- #
710
- def self.utime: ((Time | Numeric) atime, (Time | Numeric) mtime, *(string | _ToPath) file_name) -> Integer
711
-
712
- # If *file_name* is readable by others, returns an integer representing the file
713
- # permission bits of *file_name*. Returns `nil` otherwise. The meaning of the
714
- # bits is platform dependent; on Unix systems, see `stat(2)`.
715
- #
716
- # *file_name* can be an IO object.
717
- #
718
- # File.world_readable?("/etc/passwd") #=> 420
719
- # m = File.world_readable?("/etc/passwd")
720
- # sprintf("%o", m) #=> "644"
721
- #
722
- def self.world_readable?: (string | _ToPath | IO file_name) -> Integer?
723
-
724
- # If *file_name* is writable by others, returns an integer representing the file
725
- # permission bits of *file_name*. Returns `nil` otherwise. The meaning of the
726
- # bits is platform dependent; on Unix systems, see `stat(2)`.
727
- #
728
- # *file_name* can be an IO object.
729
- #
730
- # File.world_writable?("/tmp") #=> 511
731
- # m = File.world_writable?("/tmp")
732
- # sprintf("%o", m) #=> "777"
733
- #
734
- def self.world_writable?: (string | _ToPath | IO file_name) -> Integer?
735
-
736
- # Returns `true` if the named file is writable by the effective user and group
737
- # id of this process. See eaccess(3).
738
- #
739
- # Note that some OS-level security features may cause this to return true even
740
- # though the file is not writable by the effective user/group.
741
- #
742
- def self.writable?: (string | _ToPath file_name) -> bool
743
-
744
- # Returns `true` if the named file is writable by the real user and group id of
745
- # this process. See access(3).
746
- #
747
- # Note that some OS-level security features may cause this to return true even
748
- # though the file is not writable by the real user/group.
749
- #
750
- def self.writable_real?: (string | _ToPath file_name) -> bool
751
-
752
- # Returns `true` if the named file exists and has a zero size.
753
- #
754
- # *file_name* can be an IO object.
755
- #
756
- def self.zero?: (string | _ToPath | IO file_name) -> bool
757
-
758
- public
759
-
760
- # Returns the last access time (a Time object) for *file*, or epoch if *file*
761
- # has not been accessed.
762
- #
763
- # File.new("testfile").atime #=> Wed Dec 31 18:00:00 CST 1969
764
- #
765
- def atime: () -> Time
766
-
767
- # Returns the birth time for *file*.
768
- #
769
- # File.new("testfile").birthtime #=> Wed Apr 09 08:53:14 CDT 2003
770
- #
771
- # If the platform doesn't have birthtime, raises NotImplementedError.
772
- #
773
- def birthtime: () -> Time
774
-
775
- # Changes permission bits on *file* to the bit pattern represented by
776
- # *mode_int*. Actual effects are platform dependent; on Unix systems, see
777
- # `chmod(2)` for details. Follows symbolic links. Also see File#lchmod.
778
- #
779
- # f = File.new("out", "w");
780
- # f.chmod(0644) #=> 0
781
- #
782
- def chmod: (int mode) -> (0 | nil)
783
-
784
- # Changes the owner and group of *file* to the given numeric owner and group
785
- # id's. Only a process with superuser privileges may change the owner of a file.
786
- # The current owner of a file may change the file's group to any group to which
787
- # the owner belongs. A `nil` or -1 owner or group id is ignored. Follows
788
- # symbolic links. See also File#lchown.
789
- #
790
- # File.new("testfile").chown(502, 1000)
791
- #
792
- def chown: (int? owner, int? group) -> (0 | nil)
793
-
794
- # Returns the change time for *file* (that is, the time directory information
795
- # about the file was changed, not the file itself).
796
- #
797
- # Note that on Windows (NTFS), returns creation time (birth time).
798
- #
799
- # File.new("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
800
- #
801
- def ctime: () -> Time
802
-
803
- # Locks or unlocks a file according to *locking_constant* (a logical *or* of the
804
- # values in the table below). Returns `false` if File::LOCK_NB is specified and
805
- # the operation would otherwise have blocked. Not available on all platforms.
806
- #
807
- # Locking constants (in class File):
808
- #
809
- # LOCK_EX | Exclusive lock. Only one process may hold an
810
- # | exclusive lock for a given file at a time.
811
- # ----------+------------------------------------------------
812
- # LOCK_NB | Don't block when locking. May be combined
813
- # | with other lock options using logical or.
814
- # ----------+------------------------------------------------
815
- # LOCK_SH | Shared lock. Multiple processes may each hold a
816
- # | shared lock for a given file at the same time.
817
- # ----------+------------------------------------------------
818
- # LOCK_UN | Unlock.
819
- #
820
- # Example:
821
- #
822
- # # update a counter using write lock
823
- # # don't use "w" because it truncates the file before lock.
824
- # File.open("counter", File::RDWR|File::CREAT, 0644) {|f|
825
- # f.flock(File::LOCK_EX)
826
- # value = f.read.to_i + 1
827
- # f.rewind
828
- # f.write("#{value}\n")
829
- # f.flush
830
- # f.truncate(f.pos)
831
- # }
832
- #
833
- # # read the counter using read lock
834
- # File.open("counter", "r") {|f|
835
- # f.flock(File::LOCK_SH)
836
- # p f.read
837
- # }
838
- #
839
- def flock: (int locking_constant) -> (0 | false)
840
-
841
- # Same as IO#stat, but does not follow the last symbolic link. Instead, reports
842
- # on the link itself.
843
- #
844
- # File.symlink("testfile", "link2test") #=> 0
845
- # File.stat("testfile").size #=> 66
846
- # f = File.new("link2test")
847
- # f.lstat.size #=> 8
848
- # f.stat.size #=> 66
849
- #
850
- def lstat: () -> (File::Stat | nil)
851
-
852
- # Returns the modification time for *file*.
853
- #
854
- # File.new("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
855
- #
856
- def mtime: () -> Time
857
-
858
- # Returns the pathname used to create *file* as a string. Does not normalize the
859
- # name.
860
- #
861
- # The pathname may not point to the file corresponding to *file*. For instance,
862
- # the pathname becomes void when the file has been moved or deleted.
863
- #
864
- # This method raises IOError for a *file* created using File::Constants::TMPFILE
865
- # because they don't have a pathname.
866
- #
867
- # File.new("testfile").path #=> "testfile"
868
- # File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx"
869
- #
870
- def path: () -> String
871
-
872
- # Returns the size of *file* in bytes.
873
- #
874
- # File.new("testfile").size #=> 66
875
- #
876
- def size: () -> Integer
877
-
878
- # Returns the pathname used to create *file* as a string. Does not normalize the
879
- # name.
880
- #
881
- # The pathname may not point to the file corresponding to *file*. For instance,
882
- # the pathname becomes void when the file has been moved or deleted.
883
- #
884
- # This method raises IOError for a *file* created using File::Constants::TMPFILE
885
- # because they don't have a pathname.
886
- #
887
- # File.new("testfile").path #=> "testfile"
888
- # File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx"
889
- #
890
- alias to_path path
891
-
892
- # Truncates *file* to at most *integer* bytes. The file must be opened for
893
- # writing. Not available on all platforms.
894
- #
895
- # f = File.new("out", "w")
896
- # f.syswrite("1234567890") #=> 10
897
- # f.truncate(5) #=> 0
898
- # f.close() #=> nil
899
- # File.size("out") #=> 5
900
- #
901
- def truncate: (int length) -> 0
902
- end
903
-
904
- # platform specific alternative separator
905
- #
906
- #
907
- File::ALT_SEPARATOR: String?
908
-
909
- # path list separator
910
- #
911
- #
912
- File::PATH_SEPARATOR: String
913
-
914
- # separates directory parts in path
915
- #
916
- #
917
- File::SEPARATOR: String
918
-
919
- # separates directory parts in path
920
- #
921
- #
922
- File::Separator: String
923
-
924
- module File::Constants
925
- end
926
-
927
- File::Constants::APPEND: Integer
928
-
929
- File::Constants::BINARY: Integer
930
-
931
- File::Constants::CREAT: Integer
932
-
933
- File::Constants::DIRECT: Integer
934
-
935
- File::Constants::DSYNC: Integer
936
-
937
- File::Constants::EXCL: Integer
938
-
939
- File::Constants::FNM_CASEFOLD: Integer
940
-
941
- File::Constants::FNM_DOTMATCH: Integer
942
-
943
- File::Constants::FNM_EXTGLOB: Integer
944
-
945
- File::Constants::FNM_NOESCAPE: Integer
946
-
947
- File::Constants::FNM_PATHNAME: Integer
948
-
949
- File::Constants::FNM_SHORTNAME: Integer
950
-
951
- File::Constants::FNM_SYSCASE: Integer
952
-
953
- File::Constants::LOCK_EX: Integer
954
-
955
- File::Constants::LOCK_NB: Integer
956
-
957
- File::Constants::LOCK_SH: Integer
958
-
959
- File::Constants::LOCK_UN: Integer
960
-
961
- File::Constants::NOATIME: Integer
962
-
963
- File::Constants::NOCTTY: Integer
964
-
965
- File::Constants::NOFOLLOW: Integer
966
-
967
- File::Constants::NONBLOCK: Integer
968
-
969
- File::Constants::NULL: String
970
-
971
- File::Constants::RDONLY: Integer
972
-
973
- File::Constants::RDWR: Integer
974
-
975
- File::Constants::RSYNC: Integer
976
-
977
- File::Constants::SHARE_DELETE: Integer
978
-
979
- File::Constants::SYNC: Integer
980
-
981
- File::Constants::TMPFILE: Integer
982
-
983
- File::Constants::TRUNC: Integer
984
-
985
- File::Constants::WRONLY: Integer
986
-
987
- class File::Stat < Object
988
- include Comparable
989
-
990
- def initialize: (String file) -> Object
991
- def <=>: (File::Stat other) -> Integer?
992
-
993
- def atime: () -> Time
994
-
995
- def birthtime: () -> Time
996
-
997
- def blksize: () -> Integer?
998
-
999
- def blockdev?: () -> bool
1000
-
1001
- def blocks: () -> Integer?
1002
-
1003
- def chardev?: () -> bool
1004
-
1005
- def ctime: () -> Time
1006
-
1007
- def dev: () -> Integer
1008
-
1009
- def dev_major: () -> Integer
1010
-
1011
- def dev_minor: () -> Integer
1012
-
1013
- def directory?: () -> bool
1014
-
1015
- def executable?: () -> bool
1016
-
1017
- def executable_real?: () -> bool
1018
-
1019
- def file?: () -> bool
1020
-
1021
- def ftype: () -> String
1022
-
1023
- def gid: () -> Integer
1024
-
1025
- def grpowned?: () -> bool
1026
-
1027
- def ino: () -> Integer
1028
-
1029
- def inspect: () -> String
1030
-
1031
- def mode: () -> Integer
1032
-
1033
- def mtime: () -> Time
1034
-
1035
- def nlink: () -> Integer
1036
-
1037
- def owned?: () -> bool
1038
-
1039
- def pipe?: () -> bool
1040
-
1041
- def rdev: () -> Integer?
1042
-
1043
- def rdev_major: () -> Integer
1044
-
1045
- def rdev_minor: () -> Integer
1046
-
1047
- def read: (?Integer length, ?String outbuf) -> String
1048
-
1049
- def readable?: () -> bool
1050
-
1051
- def readable_real?: () -> bool
1052
-
1053
- def setgid?: () -> bool
1054
-
1055
- def setuid?: () -> bool
1056
-
1057
- def size: () -> Integer
1058
-
1059
- def socket?: () -> bool
1060
-
1061
- def sticky?: () -> bool
1062
-
1063
- def symlink?: () -> bool
1064
-
1065
- def uid: () -> Integer
1066
-
1067
- def world_readable?: () -> Integer?
1068
-
1069
- def world_writable?: () -> Integer?
1070
-
1071
- def writable?: () -> bool
1072
-
1073
- def writable_real?: () -> bool
1074
-
1075
- def zero?: () -> bool
1076
- end