steep 0.13.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +28 -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.rb +33 -1
  9. data/lib/steep/annotation_parser.rb +4 -4
  10. data/lib/steep/ast/buffer.rb +11 -7
  11. data/lib/steep/ast/builtin.rb +8 -0
  12. data/lib/steep/ast/types/factory.rb +124 -89
  13. data/lib/steep/cli.rb +16 -1
  14. data/lib/steep/drivers/annotations.rb +1 -1
  15. data/lib/steep/drivers/check.rb +20 -4
  16. data/lib/steep/drivers/init.rb +5 -5
  17. data/lib/steep/drivers/langserver.rb +13 -287
  18. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  19. data/lib/steep/drivers/vendor.rb +2 -2
  20. data/lib/steep/drivers/watch.rb +97 -85
  21. data/lib/steep/drivers/worker.rb +51 -0
  22. data/lib/steep/project.rb +9 -5
  23. data/lib/steep/project/completion_provider.rb +298 -0
  24. data/lib/steep/project/dsl.rb +14 -0
  25. data/lib/steep/project/file.rb +54 -47
  26. data/lib/steep/project/hover_content.rb +17 -8
  27. data/lib/steep/project/options.rb +25 -3
  28. data/lib/steep/project/target.rb +40 -24
  29. data/lib/steep/server/base_worker.rb +56 -0
  30. data/lib/steep/server/code_worker.rb +151 -0
  31. data/lib/steep/server/interaction_worker.rb +281 -0
  32. data/lib/steep/server/master.rb +196 -0
  33. data/lib/steep/server/signature_worker.rb +148 -0
  34. data/lib/steep/server/utils.rb +36 -0
  35. data/lib/steep/server/worker_process.rb +62 -0
  36. data/lib/steep/signature/errors.rb +1 -1
  37. data/lib/steep/signature/validator.rb +13 -13
  38. data/lib/steep/source.rb +1 -1
  39. data/lib/steep/type_construction.rb +1004 -727
  40. data/lib/steep/type_inference/constant_env.rb +3 -11
  41. data/lib/steep/type_inference/context.rb +8 -3
  42. data/lib/steep/type_inference/context_array.rb +111 -0
  43. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  44. data/lib/steep/type_inference/logic.rb +130 -0
  45. data/lib/steep/type_inference/type_env.rb +5 -69
  46. data/lib/steep/typing.rb +91 -23
  47. data/lib/steep/version.rb +1 -1
  48. data/smoke/alias/Steepfile +1 -0
  49. data/smoke/alias/a.rb +1 -1
  50. data/smoke/and/Steepfile +1 -0
  51. data/smoke/array/Steepfile +1 -0
  52. data/smoke/array/b.rb +0 -2
  53. data/smoke/block/Steepfile +1 -0
  54. data/smoke/case/Steepfile +1 -0
  55. data/smoke/class/Steepfile +1 -0
  56. data/smoke/const/Steepfile +1 -0
  57. data/smoke/dstr/Steepfile +1 -0
  58. data/smoke/ensure/Steepfile +1 -0
  59. data/smoke/enumerator/Steepfile +1 -0
  60. data/smoke/extension/Steepfile +1 -0
  61. data/smoke/extension/c.rb +1 -0
  62. data/smoke/hash/Steepfile +1 -0
  63. data/smoke/hello/Steepfile +1 -0
  64. data/smoke/if/Steepfile +1 -0
  65. data/smoke/if/a.rb +1 -1
  66. data/smoke/implements/Steepfile +1 -0
  67. data/smoke/initialize/Steepfile +1 -0
  68. data/smoke/integer/Steepfile +1 -0
  69. data/smoke/interface/Steepfile +1 -0
  70. data/smoke/kwbegin/Steepfile +1 -0
  71. data/smoke/lambda/Steepfile +1 -0
  72. data/smoke/literal/Steepfile +1 -0
  73. data/smoke/map/Steepfile +1 -0
  74. data/smoke/method/Steepfile +1 -0
  75. data/smoke/module/Steepfile +1 -0
  76. data/smoke/regexp/Steepfile +1 -0
  77. data/smoke/regexp/b.rb +4 -4
  78. data/smoke/regression/Steepfile +1 -0
  79. data/smoke/rescue/Steepfile +1 -0
  80. data/smoke/rescue/a.rb +1 -1
  81. data/smoke/self/Steepfile +1 -0
  82. data/smoke/skip/Steepfile +1 -0
  83. data/smoke/stdout/Steepfile +1 -0
  84. data/smoke/super/Steepfile +1 -0
  85. data/smoke/type_case/Steepfile +1 -0
  86. data/smoke/yield/Steepfile +1 -0
  87. data/steep.gemspec +8 -8
  88. metadata +38 -138
  89. data/exe/rbs +0 -3
  90. data/exe/ruby-signature +0 -3
  91. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  92. data/vendor/ruby-signature/.gitignore +0 -12
  93. data/vendor/ruby-signature/.rubocop.yml +0 -15
  94. data/vendor/ruby-signature/BSDL +0 -22
  95. data/vendor/ruby-signature/COPYING +0 -56
  96. data/vendor/ruby-signature/Gemfile +0 -6
  97. data/vendor/ruby-signature/README.md +0 -93
  98. data/vendor/ruby-signature/Rakefile +0 -66
  99. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
  100. data/vendor/ruby-signature/bin/console +0 -14
  101. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  102. data/vendor/ruby-signature/bin/setup +0 -10
  103. data/vendor/ruby-signature/bin/sort +0 -88
  104. data/vendor/ruby-signature/bin/test_runner.rb +0 -17
  105. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  106. data/vendor/ruby-signature/docs/sigs.md +0 -148
  107. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  108. data/vendor/ruby-signature/docs/syntax.md +0 -528
  109. data/vendor/ruby-signature/exe/rbs +0 -3
  110. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  111. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
  112. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  113. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  114. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  115. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  116. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  117. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  118. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
  119. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  120. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  121. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  122. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  123. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  124. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  125. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  126. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  127. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  128. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  129. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  130. data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
  131. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
  132. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  133. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  134. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  135. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  136. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  137. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  138. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
  139. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
  140. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  141. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  142. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  143. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  144. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  145. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  146. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  147. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
  148. data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
  149. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
  150. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
  151. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  152. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  153. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  154. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
  155. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  156. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  157. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  158. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  159. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  160. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  161. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
  162. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
  163. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  164. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  165. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  166. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  167. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
  168. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  169. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  170. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  171. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
  172. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  173. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  174. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
  175. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  176. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
  177. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  178. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
  179. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
  180. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
  181. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
  182. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
  183. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
  184. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  185. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  186. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  187. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
  188. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
  189. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
  190. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  191. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  192. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
  193. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
  194. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  195. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  196. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
  197. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
  198. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  199. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
  200. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
  201. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  202. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
  203. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
  204. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  205. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
  206. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  207. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
  208. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
  209. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
  210. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  211. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  212. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  213. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
  214. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,426 +0,0 @@
1
- # A `Proc` object is an encapsulation of a block of code, which can be
2
- # stored in a local variable, passed to a method or another
3
- # [Proc](Proc), and can be called.
4
- # [Proc](Proc) is an essential concept in Ruby and a
5
- # core of its functional programming features.
6
- #
7
- # ```ruby
8
- # square = Proc.new {|x| x**2 }
9
- #
10
- # square.call(3) #=> 9
11
- # # shorthands:
12
- # square.(3) #=> 9
13
- # square[3] #=> 9
14
- # ```
15
- #
16
- # [Proc](Proc) objects are *closures* , meaning they
17
- # remember and can use the entire context in which they were created.
18
- #
19
- # ```ruby
20
- # def gen_times(factor)
21
- # Proc.new {|n| n*factor } # remembers the value of factor at the moment of creation
22
- # end
23
- #
24
- # times3 = gen_times(3)
25
- # times5 = gen_times(5)
26
- #
27
- # times3.call(12) #=> 36
28
- # times5.call(5) #=> 25
29
- # times3.call(times5.call(4)) #=> 60
30
- # ```
31
- #
32
- #
33
- # There are several methods to create a [Proc](Proc)
34
- #
35
- # - Use the [Proc](Proc) class constructor:
36
- #
37
- # ```ruby
38
- # proc1 = Proc.new {|x| x**2 }
39
- # ```
40
- #
41
- # - Use the
42
- # [Kernel\#proc](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-proc)
43
- # method as a shorthand of
44
- # [::new](Proc#method-c-new):
45
- #
46
- # ```ruby
47
- # proc2 = proc {|x| x**2 }
48
- # ```
49
- #
50
- # - Receiving a block of code into proc argument (note the `&` ):
51
- #
52
- # ```ruby
53
- # def make_proc(&block)
54
- # block
55
- # end
56
- #
57
- # proc3 = make_proc {|x| x**2 }
58
- # ```
59
- #
60
- # - Construct a proc with lambda semantics using the
61
- # [Kernel\#lambda](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-lambda)
62
- # method (see below for explanations about lambdas):
63
- #
64
- # ```ruby
65
- # lambda1 = lambda {|x| x**2 }
66
- # ```
67
- #
68
- # - Use the Lambda literal syntax (also constructs a proc with lambda
69
- # semantics):
70
- #
71
- # ```ruby
72
- # lambda2 = ->(x) { x**2 }
73
- # ```
74
- #
75
- #
76
- # Procs are coming in two flavors: lambda and non-lambda (regular procs).
77
- # Differences are:
78
- #
79
- # - In lambdas, `return` means exit from this lambda;
80
- #
81
- # - In regular procs, `return` means exit from embracing method (and
82
- # will throw `LocalJumpError` if invoked outside the method);
83
- #
84
- # - In lambdas, arguments are treated in the same way as in methods:
85
- # strict, with `ArgumentError` for mismatching argument number, and no
86
- # additional argument processing;
87
- #
88
- # - Regular procs accept arguments more generously: missing arguments
89
- # are filled with `nil`, single
90
- # [Array](https://ruby-doc.org/core-2.6.3/Array.html) arguments are
91
- # deconstructed if the proc has multiple arguments, and there is no
92
- # error raised on extra arguments.
93
- #
94
- # Examples:
95
- #
96
- # ```ruby
97
- # p = proc {|x, y| "x=#{x}, y=#{y}" }
98
- # p.call(1, 2) #=> "x=1, y=2"
99
- # p.call([1, 2]) #=> "x=1, y=2", array deconstructed
100
- # p.call(1, 2, 8) #=> "x=1, y=2", extra argument discarded
101
- # p.call(1) #=> "x=1, y=", nil substituted instead of error
102
- #
103
- # l = lambda {|x, y| "x=#{x}, y=#{y}" }
104
- # l.call(1, 2) #=> "x=1, y=2"
105
- # l.call([1, 2]) # ArgumentError: wrong number of arguments (given 1, expected 2)
106
- # l.call(1, 2, 8) # ArgumentError: wrong number of arguments (given 3, expected 2)
107
- # l.call(1) # ArgumentError: wrong number of arguments (given 1, expected 2)
108
- #
109
- # def test_return
110
- # -> { return 3 }.call # just returns from lambda into method body
111
- # proc { return 4 }.call # returns from method
112
- # return 5
113
- # end
114
- #
115
- # test_return # => 4, return from proc
116
- # ```
117
- #
118
- # Lambdas are useful as self-sufficient functions, in particular useful as
119
- # arguments to higher-order functions, behaving exactly like Ruby methods.
120
- #
121
- # Procs are useful for implementing iterators:
122
- #
123
- # ```ruby
124
- # def test
125
- # [[1, 2], [3, 4], [5, 6]].map {|a, b| return a if a + b > 10 }
126
- # # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127
- # end
128
- # ```
129
- #
130
- # Inside `map`, the block of code is treated as a regular (non-lambda)
131
- # proc, which means that the internal arrays will be deconstructed to
132
- # pairs of arguments, and `return` will exit from the method `test` . That
133
- # would not be possible with a stricter lambda.
134
- #
135
- # You can tell a lambda from a regular proc by using the
136
- # [lambda?](Proc#method-i-lambda-3F) instance method.
137
- #
138
- # Lambda semantics is typically preserved during the proc lifetime,
139
- # including `&` -deconstruction to a block of code:
140
- #
141
- # ```ruby
142
- # p = proc {|x, y| x }
143
- # l = lambda {|x, y| x }
144
- # [[1, 2], [3, 4]].map(&p) #=> [1, 2]
145
- # [[1, 2], [3, 4]].map(&l) # ArgumentError: wrong number of arguments (given 1, expected 2)
146
- # ```
147
- #
148
- # The only exception is dynamic method definition: even if defined by
149
- # passing a non-lambda proc, methods still have normal semantics of
150
- # argument checking.
151
- #
152
- # ```ruby
153
- # class C
154
- # define_method(:e, &proc {})
155
- # end
156
- # C.new.e(1,2) #=> ArgumentError
157
- # C.new.method(:e).to_proc.lambda? #=> true
158
- # ```
159
- #
160
- # This exception ensures that methods never have unusual argument passing
161
- # conventions, and makes it easy to have wrappers defining methods that
162
- # behave as usual.
163
- #
164
- # ```ruby
165
- # class C
166
- # def self.def2(name, &body)
167
- # define_method(name, &body)
168
- # end
169
- #
170
- # def2(:f) {}
171
- # end
172
- # C.new.f(1,2) #=> ArgumentError
173
- # ```
174
- #
175
- # The wrapper *def2* receives `body` as a non-lambda proc, yet defines a
176
- # method which has normal semantics.
177
- #
178
- #
179
- # Any object that implements the `to_proc` method can be converted into a
180
- # proc by the `&` operator, and therefore con be consumed by iterators.
181
- #
182
- # ```ruby
183
- # class Greater
184
- # def initialize(greating)
185
- # @greating = greating
186
- # end
187
- #
188
- # def to_proc
189
- # proc {|name| "#{@greating}, #{name}!" }
190
- # end
191
- # end
192
- #
193
- # hi = Greater.new("Hi")
194
- # hey = Greater.new("Hey")
195
- # ["Bob", "Jane"].map(&hi) #=> ["Hi, Bob!", "Hi, Jane!"]
196
- # ["Bob", "Jane"].map(&hey) #=> ["Hey, Bob!", "Hey, Jane!"]
197
- # ```
198
- #
199
- # Of the Ruby core classes, this method is implemented by
200
- # [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html),
201
- # [Method](https://ruby-doc.org/core-2.6.3/Method.html), and
202
- # [Hash](https://ruby-doc.org/core-2.6.3/Hash.html).
203
- #
204
- # :to_s.to_proc.call(1) #=> "1"
205
- # [1, 2].map(&:to_s) #=> ["1", "2"]
206
- #
207
- # method(:puts).to_proc.call(1) # prints 1
208
- # [1, 2].each(&method(:puts)) # prints 1, 2
209
- #
210
- # {test: 1}.to_proc.call(:test) #=> 1
211
- # %i[test many keys].map(&{test: 1}) #=> [1, nil, nil]
212
- class Proc < Object
213
- # Returns the number of mandatory arguments. If the block is declared to
214
- # take no arguments, returns 0. If the block is known to take exactly n
215
- # arguments, returns n. If the block has optional arguments, returns -n-1,
216
- # where n is the number of mandatory arguments, with the exception for
217
- # blocks that are not lambdas and have only a finite number of optional
218
- # arguments; in this latter case, returns n. Keyword arguments will be
219
- # considered as a single additional argument, that argument being
220
- # mandatory if any keyword argument is mandatory. A `proc` with no
221
- # argument declarations is the same as a block declaring `||` as its
222
- # arguments.
223
- #
224
- # proc {}.arity #=> 0
225
- # proc { || }.arity #=> 0
226
- # proc { |a| }.arity #=> 1
227
- # proc { |a, b| }.arity #=> 2
228
- # proc { |a, b, c| }.arity #=> 3
229
- # proc { |*a| }.arity #=> -1
230
- # proc { |a, *b| }.arity #=> -2
231
- # proc { |a, *b, c| }.arity #=> -3
232
- # proc { |x:, y:, z:0| }.arity #=> 1
233
- # proc { |*a, x:, y:0| }.arity #=> -2
234
- #
235
- # proc { |a=0| }.arity #=> 0
236
- # lambda { |a=0| }.arity #=> -1
237
- # proc { |a=0, b| }.arity #=> 1
238
- # lambda { |a=0, b| }.arity #=> -2
239
- # proc { |a=0, b=0| }.arity #=> 0
240
- # lambda { |a=0, b=0| }.arity #=> -1
241
- # proc { |a, b=0| }.arity #=> 1
242
- # lambda { |a, b=0| }.arity #=> -2
243
- # proc { |(a, b), c=0| }.arity #=> 1
244
- # lambda { |(a, b), c=0| }.arity #=> -2
245
- # proc { |a, x:0, y:0| }.arity #=> 1
246
- # lambda { |a, x:0, y:0| }.arity #=> -2
247
- def arity: () -> Integer
248
-
249
- # Returns the binding associated with *prc* .
250
- #
251
- # ```ruby
252
- # def fred(param)
253
- # proc {}
254
- # end
255
- #
256
- # b = fred(99)
257
- # eval("param", b.binding) #=> 99
258
- # ```
259
- def binding: () -> Binding
260
-
261
- def call: (*untyped arg0) -> untyped
262
-
263
- def []: (*untyped arg0) -> untyped
264
-
265
- def curry: (?Integer arity) -> Proc
266
-
267
- # Returns a hash value corresponding to proc body.
268
- #
269
- # See also Object\#hash.
270
- def hash: () -> Integer
271
-
272
- # Returns `true` for a [Proc](Proc.downloaded.ruby_doc) object for which
273
- # argument handling is rigid. Such procs are typically generated by
274
- # `lambda` .
275
- #
276
- # A [Proc](Proc.downloaded.ruby_doc) object generated by `proc` ignores
277
- # extra arguments.
278
- #
279
- # ```ruby
280
- # proc {|a,b| [a,b] }.call(1,2,3) #=> [1,2]
281
- # ```
282
- #
283
- # It provides `nil` for missing arguments.
284
- #
285
- # ```ruby
286
- # proc {|a,b| [a,b] }.call(1) #=> [1,nil]
287
- # ```
288
- #
289
- # It expands a single array argument.
290
- #
291
- # ```ruby
292
- # proc {|a,b| [a,b] }.call([1,2]) #=> [1,2]
293
- # ```
294
- #
295
- # A [Proc](Proc.downloaded.ruby_doc) object generated by `lambda` doesn’t
296
- # have such tricks.
297
- #
298
- # ```ruby
299
- # lambda {|a,b| [a,b] }.call(1,2,3) #=> ArgumentError
300
- # lambda {|a,b| [a,b] }.call(1) #=> ArgumentError
301
- # lambda {|a,b| [a,b] }.call([1,2]) #=> ArgumentError
302
- # ```
303
- #
304
- # [\#lambda?](Proc.downloaded.ruby_doc#method-i-lambda-3F) is a predicate
305
- # for the tricks. It returns `true` if no tricks apply.
306
- #
307
- # ```ruby
308
- # lambda {}.lambda? #=> true
309
- # proc {}.lambda? #=> false
310
- # ```
311
- #
312
- # [::new](Proc.downloaded.ruby_doc#method-c-new) is the same as `proc` .
313
- #
314
- # ```ruby
315
- # Proc.new {}.lambda? #=> false
316
- # ```
317
- #
318
- # `lambda`, `proc` and [::new](Proc.downloaded.ruby_doc#method-c-new)
319
- # preserve the tricks of a [Proc](Proc.downloaded.ruby_doc) object given
320
- # by `&` argument.
321
- #
322
- # ```ruby
323
- # lambda(&lambda {}).lambda? #=> true
324
- # proc(&lambda {}).lambda? #=> true
325
- # Proc.new(&lambda {}).lambda? #=> true
326
- #
327
- # lambda(&proc {}).lambda? #=> false
328
- # proc(&proc {}).lambda? #=> false
329
- # Proc.new(&proc {}).lambda? #=> false
330
- # ```
331
- #
332
- # A [Proc](Proc.downloaded.ruby_doc) object generated by `&` argument has
333
- # the tricks
334
- #
335
- # ```ruby
336
- # def n(&b) b.lambda? end
337
- # n {} #=> false
338
- # ```
339
- #
340
- # The `&` argument preserves the tricks if a
341
- # [Proc](Proc.downloaded.ruby_doc) object is given by `&` argument.
342
- #
343
- # ```ruby
344
- # n(&lambda {}) #=> true
345
- # n(&proc {}) #=> false
346
- # n(&Proc.new {}) #=> false
347
- # ```
348
- #
349
- # A [Proc](Proc.downloaded.ruby_doc) object converted from a method has no
350
- # tricks.
351
- #
352
- # ```ruby
353
- # def m() end
354
- # method(:m).to_proc.lambda? #=> true
355
- #
356
- # n(&method(:m)) #=> true
357
- # n(&method(:m).to_proc) #=> true
358
- # ```
359
- #
360
- # `define_method` is treated the same as method definition. The defined
361
- # method has no tricks.
362
- #
363
- # ```ruby
364
- # class C
365
- # define_method(:d) {}
366
- # end
367
- # C.new.d(1,2) #=> ArgumentError
368
- # C.new.method(:d).to_proc.lambda? #=> true
369
- # ```
370
- #
371
- # `define_method` always defines a method without the tricks, even if a
372
- # non-lambda [Proc](Proc.downloaded.ruby_doc) object is given. This is the
373
- # only exception for which the tricks are not preserved.
374
- #
375
- # ```ruby
376
- # class C
377
- # define_method(:e, &proc {})
378
- # end
379
- # C.new.e(1,2) #=> ArgumentError
380
- # C.new.method(:e).to_proc.lambda? #=> true
381
- # ```
382
- #
383
- # This exception ensures that methods never have tricks and makes it easy
384
- # to have wrappers to define methods that behave as usual.
385
- #
386
- # ```ruby
387
- # class C
388
- # def self.def2(name, &body)
389
- # define_method(name, &body)
390
- # end
391
- #
392
- # def2(:f) {}
393
- # end
394
- # C.new.f(1,2) #=> ArgumentError
395
- # ```
396
- #
397
- # The wrapper *def2* defines a method which has no tricks.
398
- def lambda?: () -> bool
399
-
400
- # Returns the parameter information of this proc.
401
- #
402
- # ```ruby
403
- # prc = lambda{|x, y=42, *other|}
404
- # prc.parameters #=> [[:req, :x], [:opt, :y], [:rest, :other]]
405
- # ```
406
- def parameters: () -> ::Array[[ Symbol, Symbol ]]
407
-
408
- # Returns the Ruby source filename and line number containing this proc or
409
- # `nil` if this proc was not defined in Ruby (i.e. native).
410
- def source_location: () -> [ String, Integer ]
411
-
412
- # Part of the protocol for converting objects to `Proc` objects. Instances
413
- # of class `Proc` simply return themselves.
414
- def to_proc: () -> self
415
-
416
- # Returns the unique identifier for this proc, along with an indication of
417
- # where the proc was defined.
418
- #
419
- #
420
- #
421
- # Also aliased as: [inspect](Proc.downloaded.ruby_doc#method-i-inspect)
422
- def to_s: () -> String
423
-
424
- # Alias for: [to\_s](Proc.downloaded.ruby_doc#method-i-to_s)
425
- def inspect: () -> String
426
- end
@@ -1,354 +0,0 @@
1
- # [Module](https://ruby-doc.org/core-2.6.3/Module.html) to handle
2
- # processes.
3
- module Process
4
- # Returns the name of the script being executed. The value is not affected
5
- # by assigning a new value to $0.
6
- #
7
- # This method first appeared in Ruby 2.1 to serve as a global variable
8
- # free means to get the script name.
9
- def self.argv0: () -> String
10
-
11
- def self.clock_getres: (Symbol | Integer clock_id, ?Symbol unit) -> (Float | Integer)
12
-
13
- def self.clock_gettime: (Symbol | Integer clock_id, ?Symbol unit) -> (Float | Integer)
14
-
15
- def self.daemon: (?untyped nochdir, ?untyped noclose) -> Integer
16
-
17
- def self.detach: (Integer pid) -> Thread
18
-
19
- # Returns the effective group ID for this process. Not available on all
20
- # platforms.
21
- #
22
- # ```ruby
23
- # Process.egid #=> 500
24
- # ```
25
- def self.egid: () -> Integer
26
-
27
- def self.egid=: (Integer arg0) -> Integer
28
-
29
- # Returns the effective user ID for this process.
30
- #
31
- # ```ruby
32
- # Process.euid #=> 501
33
- # ```
34
- def self.euid: () -> Integer
35
-
36
- def self.euid=: (Integer arg0) -> Integer
37
-
38
- def self.getpgid: (Integer pid) -> Integer
39
-
40
- # Returns the process group ID for this process. Not available on all
41
- # platforms.
42
- #
43
- # ```ruby
44
- # Process.getpgid(0) #=> 25527
45
- # Process.getpgrp #=> 25527
46
- # ```
47
- def self.getpgrp: () -> Integer
48
-
49
- def self.getpriority: (Integer kind, Integer arg0) -> Integer
50
-
51
- def self.getrlimit: (Symbol | String | Integer resource) -> [ Integer, Integer ]
52
-
53
- def self.getsid: (?Integer pid) -> Integer
54
-
55
- # Returns the (real) group ID for this process.
56
- #
57
- # ```ruby
58
- # Process.gid #=> 500
59
- # ```
60
- def self.gid: () -> Integer
61
-
62
- def self.gid=: (Integer arg0) -> Integer
63
-
64
- # Get an `Array` of the group IDs in the supplemental group access list
65
- # for this process.
66
- #
67
- # ```ruby
68
- # Process.groups #=> [27, 6, 10, 11]
69
- # ```
70
- #
71
- # Note that this method is just a wrapper of getgroups(2). This means that
72
- # the following characteristics of the result completely depend on your
73
- # system:
74
- #
75
- # - the result is sorted
76
- #
77
- # - the result includes effective GIDs
78
- #
79
- # - the result does not include duplicated GIDs
80
- #
81
- # You can make sure to get a sorted unique
82
- # [GID](https://ruby-doc.org/core-2.6.3/Process/GID.html) list of the
83
- # current process by this expression:
84
- #
85
- # ```ruby
86
- # Process.groups.uniq.sort
87
- # ```
88
- def self.groups: () -> ::Array[Integer]
89
-
90
- def self.groups=: (::Array[Integer] arg0) -> ::Array[Integer]
91
-
92
- def self.initgroups: (String username, Integer gid) -> ::Array[Integer]
93
-
94
- def self.kill: (Integer | Symbol | String signal, *Integer pids) -> Integer
95
-
96
- # Returns the maximum number of gids allowed in the supplemental group
97
- # access list.
98
- #
99
- # ```ruby
100
- # Process.maxgroups #=> 32
101
- # ```
102
- def self.maxgroups: () -> Integer
103
-
104
- def self.maxgroups=: (Integer arg0) -> Integer
105
-
106
- # Returns the process id of this process. Not available on all platforms.
107
- #
108
- # ```ruby
109
- # Process.pid #=> 27415
110
- # ```
111
- def self.pid: () -> Integer
112
-
113
- # Returns the process id of the parent of this process. Returns
114
- # untrustworthy value on Win32/64. Not available on all platforms.
115
- #
116
- # ```ruby
117
- # puts "I am #{Process.pid}"
118
- # Process.fork { puts "Dad is #{Process.ppid}" }
119
- # ```
120
- #
121
- # *produces:*
122
- #
123
- # ```ruby
124
- # I am 27417
125
- # Dad is 27417
126
- # ```
127
- def self.ppid: () -> Integer
128
-
129
- def self.setpgid: (Integer pid, Integer arg0) -> Integer
130
-
131
- def self.setpriority: (Integer kind, Integer arg0, Integer priority) -> Integer
132
-
133
- def self.setproctitle: (String arg0) -> String
134
-
135
- def self.setrlimit: (Symbol | String | Integer resource, Integer cur_limit, ?Integer max_limit) -> NilClass
136
-
137
- # Establishes this process as a new session and process group leader, with
138
- # no controlling tty. Returns the session id. Not available on all
139
- # platforms.
140
- #
141
- # ```ruby
142
- # Process.setsid #=> 27422
143
- # ```
144
- def self.setsid: () -> Integer
145
-
146
- # Returns a `Tms` structure (see `Process::Tms` ) that contains user and
147
- # system CPU times for this process, and also for children processes.
148
- #
149
- # ```ruby
150
- # t = Process.times
151
- # [ t.utime, t.stime, t.cutime, t.cstime ] #=> [0.0, 0.02, 0.00, 0.00]
152
- # ```
153
- def self.times: () -> Process::Tms
154
-
155
- # Returns the (real) user ID of this process.
156
- #
157
- # ```ruby
158
- # Process.uid #=> 501
159
- # ```
160
- def self.uid: () -> Integer
161
-
162
- def self.uid=: (Integer user) -> Integer
163
-
164
- def self.wait: (?Integer pid, ?Integer flags) -> Integer
165
-
166
- def self.wait2: (?Integer pid, ?Integer flags) -> [ Integer, Process::Status ]
167
-
168
- def self.waitall: () -> ::Array[[ Integer, Process::Status ]]
169
-
170
- def self.waitpid: (?Integer pid, ?Integer flags) -> Integer
171
-
172
- def self.waitpid2: (?Integer pid, ?Integer flags) -> [ Integer, Process::Status ]
173
- end
174
-
175
- Process::CLOCK_BOOTTIME: Integer
176
-
177
- Process::CLOCK_BOOTTIME_ALARM: Integer
178
-
179
- Process::CLOCK_MONOTONIC: Integer
180
-
181
- Process::CLOCK_MONOTONIC_COARSE: Integer
182
-
183
- Process::CLOCK_MONOTONIC_RAW: Integer
184
-
185
- Process::CLOCK_PROCESS_CPUTIME_ID: Integer
186
-
187
- Process::CLOCK_REALTIME: Integer
188
-
189
- Process::CLOCK_REALTIME_ALARM: Integer
190
-
191
- Process::CLOCK_REALTIME_COARSE: Integer
192
-
193
- Process::CLOCK_THREAD_CPUTIME_ID: Integer
194
-
195
- Process::PRIO_PGRP: Integer
196
-
197
- Process::PRIO_PROCESS: Integer
198
-
199
- Process::PRIO_USER: Integer
200
-
201
- Process::RLIMIT_AS: Integer
202
-
203
- Process::RLIMIT_CORE: Integer
204
-
205
- Process::RLIMIT_CPU: Integer
206
-
207
- Process::RLIMIT_DATA: Integer
208
-
209
- Process::RLIMIT_FSIZE: Integer
210
-
211
- Process::RLIMIT_MEMLOCK: Integer
212
-
213
- Process::RLIMIT_MSGQUEUE: Integer
214
-
215
- Process::RLIMIT_NICE: Integer
216
-
217
- Process::RLIMIT_NOFILE: Integer
218
-
219
- Process::RLIMIT_NPROC: Integer
220
-
221
- Process::RLIMIT_RSS: Integer
222
-
223
- Process::RLIMIT_RTPRIO: Integer
224
-
225
- Process::RLIMIT_RTTIME: Integer
226
-
227
- Process::RLIMIT_SIGPENDING: Integer
228
-
229
- Process::RLIMIT_STACK: Integer
230
-
231
- Process::RLIM_INFINITY: Integer
232
-
233
- Process::RLIM_SAVED_CUR: Integer
234
-
235
- Process::RLIM_SAVED_MAX: Integer
236
-
237
- Process::WNOHANG: Integer
238
-
239
- Process::WUNTRACED: Integer
240
-
241
- module Process::GID
242
- def self.change_privilege: (Integer group) -> Integer
243
-
244
- def self.eid: () -> Integer
245
-
246
- def self.from_name: (String name) -> Integer
247
-
248
- def self.grant_privilege: (Integer group) -> Integer
249
-
250
- def self.re_exchange: () -> Integer
251
-
252
- def self.re_exchangeable?: () -> bool
253
-
254
- def self.rid: () -> Integer
255
-
256
- def self.sid_available?: () -> bool
257
-
258
- def self.switch: () -> Integer
259
- | [T] () { () -> T } -> T
260
-
261
- def self.eid=: (Integer group) -> Integer
262
- end
263
-
264
- class Process::Status < Object
265
- def &: (Integer num) -> Integer
266
-
267
- def ==: (untyped other) -> bool
268
-
269
- def >>: (Integer num) -> Integer
270
-
271
- def coredump?: () -> bool
272
-
273
- def exited?: () -> bool
274
-
275
- def exitstatus: () -> Integer?
276
-
277
- def inspect: () -> String
278
-
279
- def pid: () -> Integer
280
-
281
- def signaled?: () -> bool
282
-
283
- def stopped?: () -> bool
284
-
285
- def stopsig: () -> Integer?
286
-
287
- def success?: () -> bool
288
-
289
- def termsig: () -> Integer?
290
-
291
- def to_i: () -> Integer
292
-
293
- def to_s: () -> String
294
- end
295
-
296
- module Process::Sys
297
- def self.geteuid: () -> Integer
298
-
299
- def self.getgid: () -> Integer
300
-
301
- def self.getuid: () -> Integer
302
-
303
- def self.issetugid: () -> bool
304
-
305
- def self.setegid: (Integer group) -> NilClass
306
-
307
- def self.seteuid: (Integer user) -> NilClass
308
-
309
- def self.setgid: (Integer group) -> NilClass
310
-
311
- def self.setregid: (Integer rid, Integer eid) -> NilClass
312
-
313
- def self.setresgid: (Integer rid, Integer eid, Integer sid) -> NilClass
314
-
315
- def self.setresuid: (Integer rid, Integer eid, Integer sid) -> NilClass
316
-
317
- def self.setreuid: (Integer rid, Integer eid) -> NilClass
318
-
319
- def self.setrgid: (Integer group) -> NilClass
320
-
321
- def self.setruid: (Integer user) -> NilClass
322
-
323
- def self.setuid: (Integer user) -> NilClass
324
- end
325
-
326
- module Process::UID
327
- def self.change_privilege: (Integer user) -> Integer
328
-
329
- def self.eid: () -> Integer
330
-
331
- def self.from_name: (String name) -> Integer
332
-
333
- def self.grant_privilege: (Integer user) -> Integer
334
-
335
- def self.re_exchange: () -> Integer
336
-
337
- def self.re_exchangeable?: () -> bool
338
-
339
- def self.rid: () -> Integer
340
-
341
- def self.sid_available?: () -> bool
342
-
343
- def self.switch: () -> Integer
344
- | [T] () { () -> T } -> T
345
-
346
- def self.eid=: (Integer user) -> Integer
347
- end
348
-
349
- class Process::Tms < Struct[Float]
350
- end
351
-
352
- class Process::Waiter < Thread
353
- def pid: () -> Integer
354
- end