rbs 0.14.0 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +8 -4
  3. data/CHANGELOG.md +35 -0
  4. data/Gemfile +1 -0
  5. data/README.md +1 -1
  6. data/Rakefile +19 -1
  7. data/Steepfile +0 -1
  8. data/bin/test_runner.rb +15 -1
  9. data/{stdlib/builtin → core}/array.rbs +124 -120
  10. data/{stdlib/builtin → core}/basic_object.rbs +0 -0
  11. data/{stdlib/builtin → core}/binding.rbs +0 -0
  12. data/core/builtin.rbs +70 -0
  13. data/{stdlib/builtin → core}/class.rbs +0 -0
  14. data/{stdlib/builtin → core}/comparable.rbs +0 -0
  15. data/{stdlib/builtin → core}/complex.rbs +0 -0
  16. data/{stdlib/builtin → core}/constants.rbs +0 -0
  17. data/{stdlib/builtin → core}/data.rbs +0 -0
  18. data/{stdlib/builtin → core}/deprecated.rbs +0 -0
  19. data/{stdlib/builtin → core}/dir.rbs +1 -1
  20. data/{stdlib/builtin → core}/encoding.rbs +0 -0
  21. data/{stdlib/builtin → core}/enumerable.rbs +67 -60
  22. data/{stdlib/builtin → core}/enumerator.rbs +5 -5
  23. data/{stdlib/builtin → core}/errno.rbs +0 -0
  24. data/{stdlib/builtin → core}/errors.rbs +1 -1
  25. data/{stdlib/builtin → core}/exception.rbs +0 -0
  26. data/{stdlib/builtin → core}/false_class.rbs +0 -0
  27. data/{stdlib/builtin → core}/fiber.rbs +0 -0
  28. data/{stdlib/builtin → core}/fiber_error.rbs +0 -0
  29. data/{stdlib/builtin → core}/file.rbs +0 -0
  30. data/{stdlib/builtin → core}/file_test.rbs +0 -0
  31. data/{stdlib/builtin → core}/float.rbs +0 -0
  32. data/{stdlib/builtin → core}/gc.rbs +2 -2
  33. data/{stdlib/builtin → core}/hash.rbs +15 -15
  34. data/{stdlib/builtin → core}/integer.rbs +0 -0
  35. data/{stdlib/builtin → core}/io.rbs +6 -6
  36. data/{stdlib/builtin → core}/kernel.rbs +1 -85
  37. data/{stdlib/builtin → core}/marshal.rbs +0 -0
  38. data/{stdlib/builtin → core}/match_data.rbs +0 -0
  39. data/{stdlib/builtin → core}/math.rbs +0 -0
  40. data/{stdlib/builtin → core}/method.rbs +0 -0
  41. data/{stdlib/builtin → core}/module.rbs +13 -13
  42. data/{stdlib/builtin → core}/nil_class.rbs +0 -0
  43. data/{stdlib/builtin → core}/numeric.rbs +0 -0
  44. data/{stdlib/builtin → core}/object.rbs +1 -1
  45. data/core/object_space.rbs +98 -0
  46. data/{stdlib/builtin → core}/proc.rbs +0 -0
  47. data/{stdlib/builtin → core}/process.rbs +0 -0
  48. data/{stdlib/builtin → core}/random.rbs +1 -1
  49. data/{stdlib/builtin → core}/range.rbs +3 -3
  50. data/{stdlib/builtin → core}/rational.rbs +0 -0
  51. data/{stdlib/builtin → core}/rb_config.rbs +0 -0
  52. data/{stdlib/builtin → core}/regexp.rbs +0 -0
  53. data/{stdlib/builtin → core}/ruby_vm.rbs +0 -0
  54. data/{stdlib/builtin → core}/signal.rbs +0 -0
  55. data/{stdlib/builtin → core}/string.rbs +6 -6
  56. data/{stdlib/builtin → core}/string_io.rbs +7 -7
  57. data/{stdlib/builtin → core}/struct.rbs +2 -2
  58. data/{stdlib/builtin → core}/symbol.rbs +1 -1
  59. data/{stdlib/builtin → core}/thread.rbs +4 -4
  60. data/{stdlib/builtin → core}/thread_group.rbs +0 -0
  61. data/{stdlib/builtin → core}/time.rbs +0 -0
  62. data/{stdlib/builtin → core}/trace_point.rbs +0 -0
  63. data/{stdlib/builtin → core}/true_class.rbs +1 -1
  64. data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
  65. data/{stdlib/builtin → core}/warning.rbs +0 -0
  66. data/docs/repo.md +125 -0
  67. data/docs/syntax.md +50 -6
  68. data/lib/rbs.rb +1 -0
  69. data/lib/rbs/cli.rb +105 -103
  70. data/lib/rbs/definition.rb +9 -4
  71. data/lib/rbs/definition_builder.rb +50 -17
  72. data/lib/rbs/environment_loader.rb +79 -105
  73. data/lib/rbs/environment_walker.rb +70 -35
  74. data/lib/rbs/parser.rb +404 -397
  75. data/lib/rbs/parser.y +18 -9
  76. data/lib/rbs/prototype/rb.rb +186 -25
  77. data/lib/rbs/prototype/runtime.rb +18 -7
  78. data/lib/rbs/repository.rb +121 -0
  79. data/lib/rbs/test/hook.rb +27 -15
  80. data/lib/rbs/test/setup.rb +5 -3
  81. data/lib/rbs/test/tester.rb +4 -1
  82. data/lib/rbs/test/type_check.rb +16 -5
  83. data/lib/rbs/type_name.rb +2 -1
  84. data/lib/rbs/vendorer.rb +38 -16
  85. data/lib/rbs/version.rb +1 -1
  86. data/sig/cli.rbs +58 -0
  87. data/sig/constant_table.rbs +1 -1
  88. data/sig/declarations.rbs +1 -1
  89. data/sig/definition.rbs +9 -4
  90. data/sig/definition_builder.rbs +4 -1
  91. data/sig/environment_loader.rbs +92 -46
  92. data/sig/members.rbs +2 -2
  93. data/sig/method_types.rbs +1 -1
  94. data/sig/namespace.rbs +1 -1
  95. data/sig/polyfill.rbs +42 -0
  96. data/sig/rbs.rbs +8 -0
  97. data/sig/repository.rbs +79 -0
  98. data/sig/vendorer.rbs +44 -0
  99. data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
  100. data/stdlib/base64/{base64.rbs → 0/base64.rbs} +1 -1
  101. data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +0 -0
  102. data/stdlib/{bigdecimal/math → bigdecimal-math/0}/big_math.rbs +0 -0
  103. data/stdlib/bigdecimal/{big_decimal.rbs → 0/big_decimal.rbs} +0 -0
  104. data/stdlib/coverage/{coverage.rbs → 0/coverage.rbs} +2 -2
  105. data/stdlib/csv/{csv.rbs → 0/csv.rbs} +4 -4
  106. data/stdlib/date/{date.rbs → 0/date.rbs} +2 -2
  107. data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +1 -1
  108. data/stdlib/dbm/0/dbm.rbs +277 -0
  109. data/stdlib/erb/{erb.rbs → 0/erb.rbs} +0 -0
  110. data/stdlib/fiber/{fiber.rbs → 0/fiber.rbs} +0 -0
  111. data/stdlib/find/{find.rbs → 0/find.rbs} +2 -2
  112. data/stdlib/forwardable/{forwardable.rbs → 0/forwardable.rbs} +0 -0
  113. data/stdlib/ipaddr/{ipaddr.rbs → 0/ipaddr.rbs} +0 -0
  114. data/stdlib/json/{json.rbs → 0/json.rbs} +0 -0
  115. data/stdlib/logger/{formatter.rbs → 0/formatter.rbs} +0 -0
  116. data/stdlib/logger/{log_device.rbs → 0/log_device.rbs} +1 -1
  117. data/stdlib/logger/{logger.rbs → 0/logger.rbs} +1 -1
  118. data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
  119. data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
  120. data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
  121. data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +39 -39
  122. data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
  123. data/stdlib/prime/{prime.rbs → 0/prime.rbs} +1 -1
  124. data/stdlib/pstore/0/pstore.rbs +287 -0
  125. data/stdlib/pty/{pty.rbs → 0/pty.rbs} +1 -1
  126. data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
  127. data/stdlib/set/{set.rbs → 0/set.rbs} +10 -10
  128. data/stdlib/singleton/0/singleton.rbs +111 -0
  129. data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +0 -0
  130. data/stdlib/tsort/0/cyclic.rbs +4 -0
  131. data/stdlib/tsort/0/interfaces.rbs +19 -0
  132. data/stdlib/tsort/0/tsort.rbs +363 -0
  133. data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
  134. data/stdlib/uri/{generic.rbs → 0/generic.rbs} +1 -1
  135. data/stdlib/uri/{http.rbs → 0/http.rbs} +0 -0
  136. data/stdlib/uri/{https.rbs → 0/https.rbs} +0 -0
  137. data/stdlib/uri/{ldap.rbs → 0/ldap.rbs} +0 -0
  138. data/stdlib/uri/{ldaps.rbs → 0/ldaps.rbs} +0 -0
  139. data/stdlib/yaml/0/dbm.rbs +221 -0
  140. data/stdlib/yaml/0/store.rbs +53 -0
  141. data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
  142. data/steep/Gemfile.lock +9 -9
  143. metadata +108 -94
  144. data/stdlib/builtin/builtin.rbs +0 -42
@@ -0,0 +1,4 @@
1
+ module TSort[Node]
2
+ class Cyclic < StandardError
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ module TSort[Node]
2
+ interface _Sortable[Node]
3
+ # #tsort_each_node is used to iterate for all nodes over a graph.
4
+ #
5
+ def tsort_each_node: () { (Node) -> void } -> void
6
+
7
+ # #tsort_each_child is used to iterate for child nodes of node.
8
+ #
9
+ def tsort_each_child: (Node) { (Node) -> void } -> void
10
+ end
11
+
12
+ interface _EachNode[Node]
13
+ def call: () { (Node) -> void } -> void
14
+ end
15
+
16
+ interface _EachChild[Node]
17
+ def call: (Node) { (Node) -> void } -> void
18
+ end
19
+ end
@@ -0,0 +1,363 @@
1
+ # TSort implements topological sorting using Tarjan's algorithm for strongly
2
+ # connected components.
3
+ #
4
+ # TSort is designed to be able to be used with any object which can be
5
+ # interpreted as a directed graph.
6
+ #
7
+ # TSort requires two methods to interpret an object as a graph, tsort_each_node
8
+ # and tsort_each_child.
9
+ #
10
+ # * tsort_each_node is used to iterate for all nodes over a graph.
11
+ # * tsort_each_child is used to iterate for child nodes of a given node.
12
+ #
13
+ #
14
+ # The equality of nodes are defined by eql? and hash since TSort uses Hash
15
+ # internally.
16
+ #
17
+ # ## A Simple Example
18
+ #
19
+ # The following example demonstrates how to mix the TSort module into an
20
+ # existing class (in this case, Hash). Here, we're treating each key in the hash
21
+ # as a node in the graph, and so we simply alias the required #tsort_each_node
22
+ # method to Hash's #each_key method. For each key in the hash, the associated
23
+ # value is an array of the node's child nodes. This choice in turn leads to our
24
+ # implementation of the required #tsort_each_child method, which fetches the
25
+ # array of child nodes and then iterates over that array using the user-supplied
26
+ # block.
27
+ #
28
+ # require 'tsort'
29
+ #
30
+ # class Hash
31
+ # include TSort
32
+ # alias tsort_each_node each_key
33
+ # def tsort_each_child(node, &block)
34
+ # fetch(node).each(&block)
35
+ # end
36
+ # end
37
+ #
38
+ # {1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort
39
+ # #=> [3, 2, 1, 4]
40
+ #
41
+ # {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}.strongly_connected_components
42
+ # #=> [[4], [2, 3], [1]]
43
+ #
44
+ # ## A More Realistic Example
45
+ #
46
+ # A very simple `make' like tool can be implemented as follows:
47
+ #
48
+ # require 'tsort'
49
+ #
50
+ # class Make
51
+ # def initialize
52
+ # @dep = {}
53
+ # @dep.default = []
54
+ # end
55
+ #
56
+ # def rule(outputs, inputs=[], &block)
57
+ # triple = [outputs, inputs, block]
58
+ # outputs.each {|f| @dep[f] = [triple]}
59
+ # @dep[triple] = inputs
60
+ # end
61
+ #
62
+ # def build(target)
63
+ # each_strongly_connected_component_from(target) {|ns|
64
+ # if ns.length != 1
65
+ # fs = ns.delete_if {|n| Array === n}
66
+ # raise TSort::Cyclic.new("cyclic dependencies: #{fs.join ', '}")
67
+ # end
68
+ # n = ns.first
69
+ # if Array === n
70
+ # outputs, inputs, block = n
71
+ # inputs_time = inputs.map {|f| File.mtime f}.max
72
+ # begin
73
+ # outputs_time = outputs.map {|f| File.mtime f}.min
74
+ # rescue Errno::ENOENT
75
+ # outputs_time = nil
76
+ # end
77
+ # if outputs_time == nil ||
78
+ # inputs_time != nil && outputs_time <= inputs_time
79
+ # sleep 1 if inputs_time != nil && inputs_time.to_i == Time.now.to_i
80
+ # block.call
81
+ # end
82
+ # end
83
+ # }
84
+ # end
85
+ #
86
+ # def tsort_each_child(node, &block)
87
+ # @dep[node].each(&block)
88
+ # end
89
+ # include TSort
90
+ # end
91
+ #
92
+ # def command(arg)
93
+ # print arg, "\n"
94
+ # system arg
95
+ # end
96
+ #
97
+ # m = Make.new
98
+ # m.rule(%w[t1]) { command 'date > t1' }
99
+ # m.rule(%w[t2]) { command 'date > t2' }
100
+ # m.rule(%w[t3]) { command 'date > t3' }
101
+ # m.rule(%w[t4], %w[t1 t3]) { command 'cat t1 t3 > t4' }
102
+ # m.rule(%w[t5], %w[t4 t2]) { command 'cat t4 t2 > t5' }
103
+ # m.build('t5')
104
+ #
105
+ # ## Bugs
106
+ #
107
+ # * 'tsort.rb' is wrong name because this library uses Tarjan's algorithm for
108
+ # strongly connected components. Although 'strongly_connected_components.rb'
109
+ # is correct but too long.
110
+ #
111
+ #
112
+ # ## References
113
+ #
114
+ # 1. Tarjan, "Depth First Search and Linear Graph Algorithms",
115
+ #
116
+ #
117
+ # *SIAM Journal on Computing*, Vol. 1, No. 2, pp. 146-160, June 1972.
118
+ module TSort[Node] : TSort::_Sortable[Node]
119
+ # The iterator version of the TSort.strongly_connected_components method.
120
+ #
121
+ # The graph is represented by *each_node* and *each_child*. *each_node* should
122
+ # have `call` method which yields for each node in the graph. *each_child*
123
+ # should have `call` method which takes a node argument and yields for each
124
+ # child node.
125
+ #
126
+ # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
127
+ # each_node = lambda {|&b| g.each_key(&b) }
128
+ # each_child = lambda {|n, &b| g[n].each(&b) }
129
+ # TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc }
130
+ # #=> [4]
131
+ # # [2]
132
+ # # [3]
133
+ # # [1]
134
+ #
135
+ # g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
136
+ # each_node = lambda {|&b| g.each_key(&b) }
137
+ # each_child = lambda {|n, &b| g[n].each(&b) }
138
+ # TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc }
139
+ # #=> [4]
140
+ # # [2, 3]
141
+ # # [1]
142
+ #
143
+ def self.each_strongly_connected_component: [T] (_EachNode[T] each_node, _EachChild[T] each_child) { (Array[T]) -> void } -> void
144
+ | [T] (_EachNode[T] each_node, _EachChild[T] each_child) -> Enumerator[Array[T], void]
145
+
146
+ # Iterates over strongly connected components in a graph. The graph is
147
+ # represented by *node* and *each_child*.
148
+ #
149
+ # *node* is the first node. *each_child* should have `call` method which takes a
150
+ # node argument and yields for each child node.
151
+ #
152
+ # Return value is unspecified.
153
+ #
154
+ # #TSort.each_strongly_connected_component_from is a class method and it doesn't
155
+ # need a class to represent a graph which includes TSort.
156
+ #
157
+ # graph = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
158
+ # each_child = lambda {|n, &b| graph[n].each(&b) }
159
+ # TSort.each_strongly_connected_component_from(1, each_child) {|scc|
160
+ # p scc
161
+ # }
162
+ # #=> [4]
163
+ # # [2, 3]
164
+ # # [1]
165
+ #
166
+ def self.each_strongly_connected_component_from: [T] (T node, _EachChild[T] each_child, ?untyped id_map, ?untyped stack) { (Array[T]) -> void } -> void
167
+ | [T] (T node, _EachChild[T] each_child, ?untyped id_map, ?untyped stack) -> Enumerator[Array[T], void]
168
+
169
+ # Returns strongly connected components as an array of arrays of nodes. The
170
+ # array is sorted from children to parents. Each elements of the array
171
+ # represents a strongly connected component.
172
+ #
173
+ # The graph is represented by *each_node* and *each_child*. *each_node* should
174
+ # have `call` method which yields for each node in the graph. *each_child*
175
+ # should have `call` method which takes a node argument and yields for each
176
+ # child node.
177
+ #
178
+ # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
179
+ # each_node = lambda {|&b| g.each_key(&b) }
180
+ # each_child = lambda {|n, &b| g[n].each(&b) }
181
+ # p TSort.strongly_connected_components(each_node, each_child)
182
+ # #=> [[4], [2], [3], [1]]
183
+ #
184
+ # g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
185
+ # each_node = lambda {|&b| g.each_key(&b) }
186
+ # each_child = lambda {|n, &b| g[n].each(&b) }
187
+ # p TSort.strongly_connected_components(each_node, each_child)
188
+ # #=> [[4], [2, 3], [1]]
189
+ #
190
+ def self.strongly_connected_components: [T] (_EachNode[T] each_node, _EachChild[T] each_child) -> Array[Array[T]]
191
+
192
+ # Returns a topologically sorted array of nodes. The array is sorted from
193
+ # children to parents, i.e. the first element has no child and the last node has
194
+ # no parent.
195
+ #
196
+ # The graph is represented by *each_node* and *each_child*. *each_node* should
197
+ # have `call` method which yields for each node in the graph. *each_child*
198
+ # should have `call` method which takes a node argument and yields for each
199
+ # child node.
200
+ #
201
+ # If there is a cycle, TSort::Cyclic is raised.
202
+ #
203
+ # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
204
+ # each_node = lambda {|&b| g.each_key(&b) }
205
+ # each_child = lambda {|n, &b| g[n].each(&b) }
206
+ # p TSort.tsort(each_node, each_child) #=> [4, 2, 3, 1]
207
+ #
208
+ # g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
209
+ # each_node = lambda {|&b| g.each_key(&b) }
210
+ # each_child = lambda {|n, &b| g[n].each(&b) }
211
+ # p TSort.tsort(each_node, each_child) # raises TSort::Cyclic
212
+ #
213
+ def self.tsort: [T] (_EachNode[T] each_node, _EachChild[T] each_child) -> Array[T]
214
+
215
+ # The iterator version of the TSort.tsort method.
216
+ #
217
+ # The graph is represented by *each_node* and *each_child*. *each_node* should
218
+ # have `call` method which yields for each node in the graph. *each_child*
219
+ # should have `call` method which takes a node argument and yields for each
220
+ # child node.
221
+ #
222
+ # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
223
+ # each_node = lambda {|&b| g.each_key(&b) }
224
+ # each_child = lambda {|n, &b| g[n].each(&b) }
225
+ # TSort.tsort_each(each_node, each_child) {|n| p n }
226
+ # #=> 4
227
+ # # 2
228
+ # # 3
229
+ # # 1
230
+ #
231
+ def self.tsort_each: [T] (_EachNode[T] each_node, _EachChild[T] each_child) { (T) -> void } -> void
232
+ | [T] (_EachNode[T] each_node, _EachChild[T] each_child) -> Enumerator[T, void]
233
+
234
+ # The iterator version of the #strongly_connected_components method.
235
+ # *`obj*.each_strongly_connected_component` is similar to
236
+ # *`obj*.strongly_connected_components.each`, but modification of *obj* during
237
+ # the iteration may lead to unexpected results.
238
+ #
239
+ # #each_strongly_connected_component returns `nil`.
240
+ #
241
+ # class G
242
+ # include TSort
243
+ # def initialize(g)
244
+ # @g = g
245
+ # end
246
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
247
+ # def tsort_each_node(&b) @g.each_key(&b) end
248
+ # end
249
+ #
250
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
251
+ # graph.each_strongly_connected_component {|scc| p scc }
252
+ # #=> [4]
253
+ # # [2]
254
+ # # [3]
255
+ # # [1]
256
+ #
257
+ # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
258
+ # graph.each_strongly_connected_component {|scc| p scc }
259
+ # #=> [4]
260
+ # # [2, 3]
261
+ # # [1]
262
+ #
263
+ def each_strongly_connected_component: () { (Array[Node]) -> void } -> void
264
+ | () -> Enumerator[Array[Node], void]
265
+
266
+ # Iterates over strongly connected component in the subgraph reachable from
267
+ # *node*.
268
+ #
269
+ # Return value is unspecified.
270
+ #
271
+ # #each_strongly_connected_component_from doesn't call #tsort_each_node.
272
+ #
273
+ # class G
274
+ # include TSort
275
+ # def initialize(g)
276
+ # @g = g
277
+ # end
278
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
279
+ # def tsort_each_node(&b) @g.each_key(&b) end
280
+ # end
281
+ #
282
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
283
+ # graph.each_strongly_connected_component_from(2) {|scc| p scc }
284
+ # #=> [4]
285
+ # # [2]
286
+ #
287
+ # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
288
+ # graph.each_strongly_connected_component_from(2) {|scc| p scc }
289
+ # #=> [4]
290
+ # # [2, 3]
291
+ #
292
+ def each_strongly_connected_component_from: (Node, ?untyped id_map, ?untyped stack) { (Array[Node]) -> void } -> void
293
+ | (Node, ?untyped id_map, ?untyped stack) -> Enumerator[Array[Node], void]
294
+
295
+ # Returns strongly connected components as an array of arrays of nodes. The
296
+ # array is sorted from children to parents. Each elements of the array
297
+ # represents a strongly connected component.
298
+ #
299
+ # class G
300
+ # include TSort
301
+ # def initialize(g)
302
+ # @g = g
303
+ # end
304
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
305
+ # def tsort_each_node(&b) @g.each_key(&b) end
306
+ # end
307
+ #
308
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
309
+ # p graph.strongly_connected_components #=> [[4], [2], [3], [1]]
310
+ #
311
+ # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
312
+ # p graph.strongly_connected_components #=> [[4], [2, 3], [1]]
313
+ #
314
+ def strongly_connected_components: () -> Array[Array[Node]]
315
+
316
+ # Returns a topologically sorted array of nodes. The array is sorted from
317
+ # children to parents, i.e. the first element has no child and the last node has
318
+ # no parent.
319
+ #
320
+ # If there is a cycle, TSort::Cyclic is raised.
321
+ #
322
+ # class G
323
+ # include TSort
324
+ # def initialize(g)
325
+ # @g = g
326
+ # end
327
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
328
+ # def tsort_each_node(&b) @g.each_key(&b) end
329
+ # end
330
+ #
331
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
332
+ # p graph.tsort #=> [4, 2, 3, 1]
333
+ #
334
+ # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
335
+ # p graph.tsort # raises TSort::Cyclic
336
+ #
337
+ def tsort: () -> Array[Node]
338
+
339
+ # The iterator version of the #tsort method. *`obj*.tsort_each` is similar to
340
+ # *`obj*.tsort.each`, but modification of *obj* during the iteration may lead to
341
+ # unexpected results.
342
+ #
343
+ # #tsort_each returns `nil`. If there is a cycle, TSort::Cyclic is raised.
344
+ #
345
+ # class G
346
+ # include TSort
347
+ # def initialize(g)
348
+ # @g = g
349
+ # end
350
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
351
+ # def tsort_each_node(&b) @g.each_key(&b) end
352
+ # end
353
+ #
354
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
355
+ # graph.tsort_each {|n| p n }
356
+ # #=> 4
357
+ # # 2
358
+ # # 3
359
+ # # 1
360
+ #
361
+ def tsort_each: () { (Node) -> void } -> void
362
+ | () -> Enumerator[Node, void]
363
+ end
File without changes
@@ -193,7 +193,7 @@ module URI
193
193
  #
194
194
  # Creates a new URI::Generic instance from ``generic'' components without check.
195
195
  #
196
- def initialize: (String scheme, String userinfo, String host, Integer port, String? registry, String path, String? opaque, String query, String fragment, ?untyped parser, ?bool arg_check) -> URI::Generic
196
+ def initialize: (String scheme, String userinfo, String host, Integer port, String? registry, String path, String? opaque, String query, String fragment, ?untyped parser, ?boolish arg_check) -> URI::Generic
197
197
 
198
198
  #
199
199
  # Returns the scheme component of the URI.
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,221 @@
1
+ # YAML Ain't Markup Language
2
+ #
3
+ # This module provides a Ruby interface for data serialization in YAML format.
4
+ #
5
+ # The YAML module is an alias of Psych, the YAML engine for Ruby.
6
+ #
7
+ # ## Usage
8
+ #
9
+ # Working with YAML can be very simple, for example:
10
+ #
11
+ # require 'yaml'
12
+ # # Parse a YAML string
13
+ # YAML.load("--- foo") #=> "foo"
14
+ #
15
+ # # Emit some YAML
16
+ # YAML.dump("foo") # => "--- foo\n...\n"
17
+ # { :a => 'b'}.to_yaml # => "---\n:a: b\n"
18
+ #
19
+ # As the implementation is provided by the Psych library, detailed documentation
20
+ # can be found in that library's docs (also part of standard library).
21
+ #
22
+ # ## Security
23
+ #
24
+ # Do not use YAML to load untrusted data. Doing so is unsafe and could allow
25
+ # malicious input to execute arbitrary code inside your application. Please see
26
+ # doc/security.rdoc for more information.
27
+ #
28
+ # ## History
29
+ #
30
+ # Syck was the original for YAML implementation in Ruby's standard library
31
+ # developed by why the lucky stiff.
32
+ #
33
+ # You can still use Syck, if you prefer, for parsing and emitting YAML, but you
34
+ # must install the 'syck' gem now in order to use it.
35
+ #
36
+ # In older Ruby versions, ie. <= 1.9, Syck is still provided, however it was
37
+ # completely removed with the release of Ruby 2.0.0.
38
+ #
39
+ # ## More info
40
+ #
41
+ # For more advanced details on the implementation see Psych, and also check out
42
+ # http://yaml.org for spec details and other helpful information.
43
+ #
44
+ # Psych is maintained by Aaron Patterson on github:
45
+ # https://github.com/ruby/psych
46
+ #
47
+ # Syck can also be found on github: https://github.com/ruby/syck
48
+ #
49
+ module YAML
50
+ # YAML + DBM = YDBM
51
+ #
52
+ # YAML::DBM provides the same interface as ::DBM.
53
+ #
54
+ # However, while DBM only allows strings for both keys and values,
55
+ # this library allows one to use most Ruby objects for values
56
+ # by first converting them to YAML. Keys must be strings.
57
+ #
58
+ # Conversion to and from YAML is performed automatically.
59
+ #
60
+ # See the documentation for ::DBM and ::YAML for more information.
61
+ class DBM < ::DBM
62
+ VERSION: ::String
63
+
64
+ # :call-seq:
65
+ # ydbm[key] -> value
66
+ #
67
+ # Return value associated with +key+ from database.
68
+ #
69
+ # Returns +nil+ if there is no such +key+.
70
+ #
71
+ # See #fetch for more information.
72
+ def []: (String key) -> untyped
73
+
74
+ # :call-seq:
75
+ # ydbm[key] = value
76
+ #
77
+ # Set +key+ to +value+ in database.
78
+ #
79
+ # +value+ will be converted to YAML before storage.
80
+ #
81
+ # See #store for more information.
82
+ def []=: (String key, untyped val) -> untyped
83
+
84
+ # :call-seq:
85
+ # ydbm.fetch( key, ifnone = nil )
86
+ # ydbm.fetch( key ) { |key| ... }
87
+ #
88
+ # Return value associated with +key+.
89
+ #
90
+ # If there is no value for +key+ and no block is given, returns +ifnone+.
91
+ #
92
+ # Otherwise, calls block passing in the given +key+.
93
+ #
94
+ # See ::DBM#fetch for more information.
95
+ def fetch: (String keystr, ?untyped? ifnone) { (untyped) -> untyped } -> untyped
96
+
97
+ # Deprecated, used YAML::DBM#key instead.
98
+ # ----
99
+ # Note:
100
+ # YAML::DBM#index makes warning from internal of ::DBM#index.
101
+ # It says 'DBM#index is deprecated; use DBM#key', but DBM#key
102
+ # behaves not same as DBM#index.
103
+ #
104
+ def index: (String keystr) -> untyped
105
+
106
+ # :call-seq:
107
+ # ydbm.key(value) -> string
108
+ #
109
+ # Returns the key for the specified value.
110
+ def key: (String keystr) -> String
111
+
112
+ # :call-seq:
113
+ # ydbm.values_at(*keys)
114
+ #
115
+ # Returns an array containing the values associated with the given keys.
116
+ def values_at: (*untyped keys) -> Array[untyped]
117
+
118
+ # :call-seq:
119
+ # ydbm.delete(key)
120
+ #
121
+ # Deletes value from database associated with +key+.
122
+ #
123
+ # Returns value or +nil+.
124
+ def delete: (String key) -> untyped
125
+
126
+ def delete_if: () { (untyped, untyped) -> untyped } -> untyped
127
+
128
+ # :call-seq:
129
+ # ydbm.reject { |key, value| ... }
130
+ #
131
+ # Converts the contents of the database to an in-memory Hash, then calls
132
+ # Hash#reject with the specified code block, returning a new Hash.
133
+ def reject: () { (untyped, untyped) -> untyped } -> Hash[untyped, untyped]
134
+
135
+ def each_pair: () { (untyped, untyped) -> untyped } -> untyped
136
+
137
+ def each_value: () { (untyped) -> untyped } -> untyped
138
+
139
+ # :call-seq:
140
+ # ydbm.values
141
+ #
142
+ # Returns an array of values from the database.
143
+ def values: () -> untyped
144
+
145
+ # :call-seq:
146
+ # ydbm.has_value?(value)
147
+ #
148
+ # Returns true if specified +value+ is found in the database.
149
+ def has_value?: (untyped val) -> (::TrueClass | ::FalseClass)
150
+
151
+ # :call-seq:
152
+ # ydbm.invert -> hash
153
+ #
154
+ # Returns a Hash (not a DBM database) created by using each value in the
155
+ # database as a key, with the corresponding key as its value.
156
+ #
157
+ # Note that all values in the hash will be Strings, but the keys will be
158
+ # actual objects.
159
+ def invert: () -> Hash[untyped, untyped]
160
+
161
+ # :call-seq:
162
+ # ydbm.replace(hash) -> ydbm
163
+ #
164
+ # Replaces the contents of the database with the contents of the specified
165
+ # object. Takes any object which implements the each_pair method, including
166
+ # Hash and DBM objects.
167
+ def replace: (Hash[untyped, untyped] | DBM hsh) -> YAML::DBM
168
+
169
+ # :call-seq:
170
+ # ydbm.shift -> [key, value]
171
+ #
172
+ # Removes a [key, value] pair from the database, and returns it.
173
+ # If the database is empty, returns +nil+.
174
+ #
175
+ # The order in which values are removed/returned is not guaranteed.
176
+ def shift: () -> (Array[untyped] | untyped)
177
+
178
+ # :call-seq:
179
+ # ydbm.select { |key, value| ... }
180
+ # ydbm.select(*keys)
181
+ #
182
+ # If a block is provided, returns a new array containing [key, value] pairs
183
+ # for which the block returns true.
184
+ #
185
+ # Otherwise, same as #values_at
186
+ def select: (*untyped keys) { (untyped, untyped) -> untyped } -> Array[untyped]
187
+
188
+ # :call-seq:
189
+ # ydbm.store(key, value) -> value
190
+ #
191
+ # Stores +value+ in database with +key+ as the index. +value+ is converted
192
+ # to YAML before being stored.
193
+ #
194
+ # Returns +value+
195
+ def store: (String key, untyped val) -> untyped
196
+
197
+ # :call-seq:
198
+ # ydbm.update(hash) -> ydbm
199
+ #
200
+ # Updates the database with multiple values from the specified object.
201
+ # Takes any object which implements the each_pair method, including
202
+ # Hash and DBM objects.
203
+ #
204
+ # Returns +self+.
205
+ def update: (Hash[untyped, untyped]) -> YAML::DBM
206
+
207
+ # :call-seq:
208
+ # ydbm.to_a -> array
209
+ #
210
+ # Converts the contents of the database to an array of [key, value] arrays,
211
+ # and returns it.
212
+ def to_a: () -> Array [untyped]
213
+
214
+ # :call-seq:
215
+ # ydbm.to_hash -> hash
216
+ #
217
+ # Converts the contents of the database to an in-memory Hash object, and
218
+ # returns it.
219
+ def to_hash: () -> Hash[untyped, untyped]
220
+ end
221
+ end