steep 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (299) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +27 -0
  3. data/.gitmodules +3 -0
  4. data/CHANGELOG.md +5 -0
  5. data/README.md +48 -90
  6. data/Rakefile +10 -6
  7. data/Steepfile +1 -0
  8. data/bin/setup +1 -0
  9. data/bin/smoke_runner.rb +9 -14
  10. data/exe/rbs +3 -0
  11. data/exe/ruby-signature +3 -0
  12. data/exe/steep +1 -0
  13. data/lib/steep.rb +32 -26
  14. data/lib/steep/annotation_parser.rb +167 -0
  15. data/lib/steep/ast/annotation/collection.rb +7 -7
  16. data/lib/steep/ast/types.rb +60 -0
  17. data/lib/steep/ast/types/any.rb +1 -1
  18. data/lib/steep/ast/types/factory.rb +535 -0
  19. data/lib/steep/ast/types/name.rb +3 -3
  20. data/lib/steep/ast/types/var.rb +1 -1
  21. data/lib/steep/cli.rb +56 -240
  22. data/lib/steep/drivers/annotations.rb +36 -19
  23. data/lib/steep/drivers/check.rb +55 -91
  24. data/lib/steep/drivers/init.rb +54 -0
  25. data/lib/steep/drivers/langserver.rb +241 -150
  26. data/lib/steep/drivers/print_project.rb +56 -0
  27. data/lib/steep/drivers/signature_error_printer.rb +25 -0
  28. data/lib/steep/drivers/trace_printer.rb +25 -0
  29. data/lib/steep/drivers/utils/driver_helper.rb +26 -0
  30. data/lib/steep/drivers/validate.rb +18 -38
  31. data/lib/steep/drivers/vendor.rb +46 -0
  32. data/lib/steep/drivers/watch.rb +78 -140
  33. data/lib/steep/errors.rb +22 -13
  34. data/lib/steep/interface/interface.rb +91 -0
  35. data/lib/steep/interface/method.rb +0 -4
  36. data/lib/steep/interface/method_type.rb +362 -2
  37. data/lib/steep/interface/substitution.rb +22 -0
  38. data/lib/steep/project.rb +25 -233
  39. data/lib/steep/project/dsl.rb +132 -0
  40. data/lib/steep/project/file.rb +93 -76
  41. data/lib/steep/project/file_loader.rb +63 -0
  42. data/lib/steep/project/options.rb +7 -0
  43. data/lib/steep/project/target.rb +190 -0
  44. data/lib/steep/signature/errors.rb +25 -77
  45. data/lib/steep/signature/validator.rb +122 -0
  46. data/lib/steep/source.rb +12 -7
  47. data/lib/steep/subtyping/check.rb +357 -633
  48. data/lib/steep/subtyping/constraints.rb +2 -2
  49. data/lib/steep/subtyping/trace.rb +23 -0
  50. data/lib/steep/type_construction.rb +509 -455
  51. data/lib/steep/type_inference/constant_env.rb +16 -24
  52. data/lib/steep/type_inference/type_env.rb +26 -18
  53. data/lib/steep/version.rb +1 -1
  54. data/sample/Steepfile +6 -0
  55. data/sample/lib/conference.rb +12 -0
  56. data/sample/sig/conference.rbs +6 -0
  57. data/smoke/alias/Steepfile +4 -0
  58. data/smoke/alias/a.rb +2 -2
  59. data/smoke/alias/{a.rbi → a.rbs} +1 -1
  60. data/smoke/and/Steepfile +4 -0
  61. data/smoke/array/Steepfile +4 -0
  62. data/smoke/array/a.rb +2 -2
  63. data/smoke/array/b.rb +4 -4
  64. data/smoke/array/c.rb +2 -2
  65. data/smoke/block/Steepfile +5 -0
  66. data/smoke/block/{a.rbi → a.rbs} +1 -1
  67. data/smoke/block/{c.rbi → c.rbs} +0 -0
  68. data/smoke/block/d.rb +6 -6
  69. data/smoke/case/Steepfile +4 -0
  70. data/smoke/case/a.rb +4 -3
  71. data/smoke/class/Steepfile +4 -0
  72. data/smoke/class/a.rb +1 -4
  73. data/smoke/class/a.rbs +24 -0
  74. data/smoke/class/h.rb +6 -2
  75. data/smoke/class/{h.rbi → h.rbs} +1 -2
  76. data/smoke/class/i.rb +1 -2
  77. data/smoke/class/i.rbs +9 -0
  78. data/smoke/const/Steepfile +4 -0
  79. data/smoke/dstr/Steepfile +4 -0
  80. data/smoke/ensure/Steepfile +4 -0
  81. data/smoke/ensure/a.rb +1 -1
  82. data/smoke/enumerator/Steepfile +4 -0
  83. data/smoke/enumerator/a.rb +7 -7
  84. data/smoke/enumerator/b.rb +6 -6
  85. data/smoke/extension/Steepfile +4 -0
  86. data/smoke/extension/{a.rbi → a.rbs} +2 -2
  87. data/smoke/extension/{e.rbi → e.rbs} +2 -2
  88. data/smoke/hash/Steepfile +4 -0
  89. data/smoke/hash/{a.rbi → a.rbs} +0 -0
  90. data/smoke/hash/b.rb +2 -2
  91. data/smoke/hash/c.rb +1 -1
  92. data/smoke/hash/e.rbs +3 -0
  93. data/smoke/hash/f.rb +1 -1
  94. data/smoke/hello/Steepfile +4 -0
  95. data/smoke/hello/hello.rbs +7 -0
  96. data/smoke/if/Steepfile +4 -0
  97. data/smoke/implements/Steepfile +4 -0
  98. data/smoke/implements/a.rbs +6 -0
  99. data/smoke/initialize/Steepfile +4 -0
  100. data/smoke/initialize/a.rbs +3 -0
  101. data/smoke/integer/Steepfile +4 -0
  102. data/smoke/integer/a.rb +5 -3
  103. data/smoke/interface/Steepfile +4 -0
  104. data/smoke/interface/{a.rbi → a.rbs} +0 -0
  105. data/smoke/kwbegin/Steepfile +4 -0
  106. data/smoke/lambda/Steepfile +4 -0
  107. data/smoke/lambda/a.rb +9 -2
  108. data/smoke/literal/Steepfile +4 -0
  109. data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
  110. data/smoke/map/Steepfile +4 -0
  111. data/smoke/map/a.rb +1 -1
  112. data/smoke/method/Steepfile +4 -0
  113. data/smoke/method/{a.rbi → a.rbs} +0 -0
  114. data/smoke/method/b.rb +1 -4
  115. data/smoke/method/d.rb +1 -0
  116. data/smoke/method/d.rbs +3 -0
  117. data/smoke/module/Steepfile +4 -0
  118. data/smoke/module/a.rb +1 -1
  119. data/smoke/module/a.rbs +16 -0
  120. data/smoke/module/c.rb +1 -1
  121. data/smoke/regexp/Steepfile +4 -0
  122. data/smoke/regexp/a.rb +2 -2
  123. data/smoke/regexp/b.rb +16 -16
  124. data/smoke/regression/Steepfile +5 -0
  125. data/smoke/regression/array.rb +2 -2
  126. data/smoke/regression/hash.rb +2 -2
  127. data/smoke/regression/poly_new.rb +2 -0
  128. data/smoke/regression/poly_new.rbs +4 -0
  129. data/smoke/regression/set_divide.rb +2 -2
  130. data/smoke/rescue/Steepfile +4 -0
  131. data/smoke/rescue/a.rb +1 -1
  132. data/smoke/self/Steepfile +4 -0
  133. data/smoke/self/a.rbs +4 -0
  134. data/smoke/skip/Steepfile +4 -0
  135. data/smoke/stdout/Steepfile +4 -0
  136. data/smoke/stdout/{a.rbi → a.rbs} +1 -1
  137. data/smoke/super/Steepfile +4 -0
  138. data/smoke/super/a.rbs +10 -0
  139. data/smoke/type_case/Steepfile +4 -0
  140. data/smoke/type_case/a.rb +1 -1
  141. data/smoke/yield/Steepfile +4 -0
  142. data/smoke/yield/a.rb +2 -2
  143. data/steep.gemspec +14 -7
  144. data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
  145. data/vendor/ruby-signature/.gitignore +12 -0
  146. data/vendor/ruby-signature/.rubocop.yml +15 -0
  147. data/vendor/ruby-signature/BSDL +22 -0
  148. data/vendor/ruby-signature/COPYING +56 -0
  149. data/vendor/ruby-signature/Gemfile +6 -0
  150. data/vendor/ruby-signature/README.md +93 -0
  151. data/vendor/ruby-signature/Rakefile +66 -0
  152. data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
  153. data/vendor/ruby-signature/bin/console +14 -0
  154. data/vendor/ruby-signature/bin/query-rdoc +103 -0
  155. data/vendor/ruby-signature/bin/setup +10 -0
  156. data/vendor/ruby-signature/bin/sort +88 -0
  157. data/vendor/ruby-signature/bin/test_runner.rb +17 -0
  158. data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
  159. data/vendor/ruby-signature/docs/sigs.md +148 -0
  160. data/vendor/ruby-signature/docs/stdlib.md +152 -0
  161. data/vendor/ruby-signature/docs/syntax.md +528 -0
  162. data/vendor/ruby-signature/exe/rbs +3 -0
  163. data/vendor/ruby-signature/exe/ruby-signature +7 -0
  164. data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
  165. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
  166. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
  167. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
  168. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
  169. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
  170. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
  171. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
  172. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
  173. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
  174. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
  175. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
  176. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
  177. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
  178. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
  179. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
  180. data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
  181. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
  182. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
  183. data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
  184. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
  185. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
  186. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
  187. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
  188. data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
  189. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
  190. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
  191. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
  192. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
  193. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
  194. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
  195. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
  196. data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
  197. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
  198. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
  199. data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
  200. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
  201. data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
  202. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
  203. data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
  204. data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
  205. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
  206. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
  207. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
  208. data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
  209. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
  210. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
  211. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
  212. data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
  213. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
  214. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
  215. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
  216. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
  217. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
  218. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
  219. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
  220. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
  221. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
  222. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
  223. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
  224. data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
  225. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
  226. data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
  227. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
  228. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
  229. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
  230. data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
  231. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
  232. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
  233. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
  234. data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
  235. data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
  236. data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
  237. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
  238. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
  239. data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
  240. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
  241. data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
  242. data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
  243. data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
  244. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
  245. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
  246. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
  247. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
  248. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
  249. data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
  250. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
  251. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
  252. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
  253. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
  254. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
  255. data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
  256. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
  257. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
  258. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
  259. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
  260. data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
  261. data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
  262. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
  263. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
  264. data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
  265. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
  266. data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
  267. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
  268. metadata +244 -54
  269. data/.travis.yml +0 -7
  270. data/lib/steep/ast/signature/alias.rb +0 -19
  271. data/lib/steep/ast/signature/class.rb +0 -33
  272. data/lib/steep/ast/signature/const.rb +0 -17
  273. data/lib/steep/ast/signature/env.rb +0 -138
  274. data/lib/steep/ast/signature/extension.rb +0 -21
  275. data/lib/steep/ast/signature/gvar.rb +0 -17
  276. data/lib/steep/ast/signature/interface.rb +0 -31
  277. data/lib/steep/ast/signature/members.rb +0 -115
  278. data/lib/steep/ast/signature/module.rb +0 -21
  279. data/lib/steep/drivers/print_interface.rb +0 -94
  280. data/lib/steep/drivers/scaffold.rb +0 -321
  281. data/lib/steep/drivers/utils/each_signature.rb +0 -31
  282. data/lib/steep/interface/abstract.rb +0 -68
  283. data/lib/steep/interface/builder.rb +0 -637
  284. data/lib/steep/interface/instantiated.rb +0 -163
  285. data/lib/steep/interface/ivar_chain.rb +0 -26
  286. data/lib/steep/parser.y +0 -1278
  287. data/lib/steep/project/listener.rb +0 -53
  288. data/smoke/class/a.rbi +0 -24
  289. data/smoke/class/d.rb +0 -9
  290. data/smoke/class/e.rb +0 -12
  291. data/smoke/class/i.rbi +0 -9
  292. data/smoke/hash/e.rbi +0 -3
  293. data/smoke/hello/hello.rbi +0 -7
  294. data/smoke/implements/a.rbi +0 -6
  295. data/smoke/initialize/a.rbi +0 -3
  296. data/smoke/module/a.rbi +0 -16
  297. data/smoke/self/a.rbi +0 -4
  298. data/smoke/super/a.rbi +0 -10
  299. data/stdlib/builtin.rbi +0 -787
@@ -0,0 +1,121 @@
1
+ # The [GC](GC) module provides an interface to Ruby’s
2
+ # mark and sweep garbage collection mechanism.
3
+ #
4
+ # Some of the underlying methods are also available via the
5
+ # [ObjectSpace](https://ruby-doc.org/core-2.6.3/ObjectSpace.html) module.
6
+ #
7
+ # You may obtain information about the operation of the
8
+ # [GC](GC) through
9
+ # [GC::Profiler](https://ruby-doc.org/core-2.6.3/GC/Profiler.html).
10
+ module GC
11
+ # The number of times [GC](GC.downloaded.ruby_doc) occurred.
12
+ #
13
+ # It returns the number of times [GC](GC.downloaded.ruby_doc) occurred
14
+ # since the process started.
15
+ def self.count: () -> Integer
16
+
17
+ # Disables garbage collection, returning `true` if garbage collection was
18
+ # already disabled.
19
+ #
20
+ # ```ruby
21
+ # GC.disable #=> false
22
+ # GC.disable #=> true
23
+ # ```
24
+ def self.disable: () -> bool
25
+
26
+ # Enables garbage collection, returning `true` if garbage collection was
27
+ # previously disabled.
28
+ #
29
+ # ```ruby
30
+ # GC.disable #=> false
31
+ # GC.enable #=> true
32
+ # GC.enable #=> false
33
+ # ```
34
+ def self.enable: () -> bool
35
+
36
+ def self.start: (?full_mark: bool full_mark, ?immediate_mark: bool immediate_mark, ?immediate_sweep: bool immediate_sweep) -> nil
37
+
38
+ # Returns a [Hash](https://ruby-doc.org/core-2.6.3/Hash.html) containing
39
+ # information about the [GC](GC.downloaded.ruby_doc).
40
+ #
41
+ # The hash includes information about internal statistics about
42
+ # [GC](GC.downloaded.ruby_doc) such as:
43
+ #
44
+ # ```ruby
45
+ # {
46
+ # :count=>0,
47
+ # :heap_allocated_pages=>24,
48
+ # :heap_sorted_length=>24,
49
+ # :heap_allocatable_pages=>0,
50
+ # :heap_available_slots=>9783,
51
+ # :heap_live_slots=>7713,
52
+ # :heap_free_slots=>2070,
53
+ # :heap_final_slots=>0,
54
+ # :heap_marked_slots=>0,
55
+ # :heap_eden_pages=>24,
56
+ # :heap_tomb_pages=>0,
57
+ # :total_allocated_pages=>24,
58
+ # :total_freed_pages=>0,
59
+ # :total_allocated_objects=>7796,
60
+ # :total_freed_objects=>83,
61
+ # :malloc_increase_bytes=>2389312,
62
+ # :malloc_increase_bytes_limit=>16777216,
63
+ # :minor_gc_count=>0,
64
+ # :major_gc_count=>0,
65
+ # :remembered_wb_unprotected_objects=>0,
66
+ # :remembered_wb_unprotected_objects_limit=>0,
67
+ # :old_objects=>0,
68
+ # :old_objects_limit=>0,
69
+ # :oldmalloc_increase_bytes=>2389760,
70
+ # :oldmalloc_increase_bytes_limit=>16777216
71
+ # }
72
+ # ```
73
+ #
74
+ # The contents of the hash are implementation specific and may be changed
75
+ # in the future.
76
+ #
77
+ # This method is only expected to work on C Ruby.
78
+ def self.stat: (?::Hash[Symbol, Integer] arg0) -> ::Hash[Symbol, Integer]
79
+ | (?Symbol arg0) -> Integer
80
+
81
+ # Returns current status of [GC](GC.downloaded.ruby_doc) stress mode.
82
+ def self.stress: () -> (Integer | TrueClass | FalseClass)
83
+
84
+ def self.stress=: ((Integer | TrueClass | FalseClass) flag) -> (Integer | TrueClass | FalseClass)
85
+
86
+ def self.compact: () -> ::Hash[:considered | :moved, Hash[Symbol | Integer, Integer]]
87
+
88
+ def self.verify_compaction_references: () -> ::Hash[:considered | :moved, Hash[Symbol | Integer, Integer]]
89
+
90
+ def self.verify_internal_consistency: () -> nil
91
+
92
+ def self.verify_transient_heap_internal_consistency: () -> nil
93
+
94
+ def self.latest_gc_info: () -> ::Hash[::Symbol, untyped]
95
+ | [K] (?Hash[K, untyped] hash) -> ::Hash[::Symbol | K, untyped]
96
+ | (Symbol key) -> untyped
97
+
98
+ def garbage_collect: (?full_mark: bool full_mark, ?immediate_mark: bool immediate_mark, ?immediate_sweep: bool immediate_sweep) -> nil
99
+ end
100
+
101
+ GC::INTERNAL_CONSTANTS: Hash[Symbol, Integer]
102
+
103
+ GC::OPTS: Array[String]
104
+
105
+ module GC::Profiler
106
+ def self.clear: () -> void
107
+
108
+ def self.disable: () -> void
109
+
110
+ def self.enable: () -> void
111
+
112
+ def self.enabled?: () -> bool
113
+
114
+ def self.raw_data: () -> ::Array[::Hash[Symbol, untyped]]
115
+
116
+ def self.report: (?IO io) -> void
117
+
118
+ def self.result: () -> String
119
+
120
+ def self.total_time: () -> Float
121
+ end
@@ -0,0 +1,1029 @@
1
+ # A Hash is a dictionary-like collection of unique keys and their values. Also
2
+ # called associative arrays, they are similar to Arrays, but where an Array uses
3
+ # integers as its index, a Hash allows you to use any object type.
4
+ #
5
+ # Hashes enumerate their values in the order that the corresponding keys were
6
+ # inserted.
7
+ #
8
+ # A Hash can be easily created by using its implicit form:
9
+ #
10
+ # grades = { "Jane Doe" => 10, "Jim Doe" => 6 }
11
+ #
12
+ # Hashes allow an alternate syntax for keys that are symbols. Instead of
13
+ #
14
+ # options = { :font_size => 10, :font_family => "Arial" }
15
+ #
16
+ # You could write it as:
17
+ #
18
+ # options = { font_size: 10, font_family: "Arial" }
19
+ #
20
+ # Each named key is a symbol you can access in hash:
21
+ #
22
+ # options[:font_size] # => 10
23
+ #
24
+ # A Hash can also be created through its ::new method:
25
+ #
26
+ # grades = Hash.new
27
+ # grades["Dorothy Doe"] = 9
28
+ #
29
+ # Hashes have a *default value* that is returned when accessing keys that do not
30
+ # exist in the hash. If no default is set `nil` is used. You can set the default
31
+ # value by sending it as an argument to Hash.new:
32
+ #
33
+ # grades = Hash.new(0)
34
+ #
35
+ # Or by using the #default= method:
36
+ #
37
+ # grades = {"Timmy Doe" => 8}
38
+ # grades.default = 0
39
+ #
40
+ # Accessing a value in a Hash requires using its key:
41
+ #
42
+ # puts grades["Jane Doe"] # => 0
43
+ #
44
+ # ### Common Uses
45
+ #
46
+ # Hashes are an easy way to represent data structures, such as
47
+ #
48
+ # books = {}
49
+ # books[:matz] = "The Ruby Programming Language"
50
+ # books[:black] = "The Well-Grounded Rubyist"
51
+ #
52
+ # Hashes are also commonly used as a way to have named parameters in functions.
53
+ # Note that no brackets are used below. If a hash is the last argument on a
54
+ # method call, no braces are needed, thus creating a really clean interface:
55
+ #
56
+ # Person.create(name: "John Doe", age: 27)
57
+ #
58
+ # def self.create(params)
59
+ # @name = params[:name]
60
+ # @age = params[:age]
61
+ # end
62
+ #
63
+ # ### Hash Keys
64
+ #
65
+ # Two objects refer to the same hash key when their `hash` value is identical
66
+ # and the two objects are `eql?` to each other.
67
+ #
68
+ # A user-defined class may be used as a hash key if the `hash` and `eql?`
69
+ # methods are overridden to provide meaningful behavior. By default, separate
70
+ # instances refer to separate hash keys.
71
+ #
72
+ # A typical implementation of `hash` is based on the object's data while `eql?`
73
+ # is usually aliased to the overridden `==` method:
74
+ #
75
+ # class Book
76
+ # attr_reader :author, :title
77
+ #
78
+ # def initialize(author, title)
79
+ # @author = author
80
+ # @title = title
81
+ # end
82
+ #
83
+ # def ==(other)
84
+ # self.class === other and
85
+ # other.author == @author and
86
+ # other.title == @title
87
+ # end
88
+ #
89
+ # alias eql? ==
90
+ #
91
+ # def hash
92
+ # @author.hash ^ @title.hash # XOR
93
+ # end
94
+ # end
95
+ #
96
+ # book1 = Book.new 'matz', 'Ruby in a Nutshell'
97
+ # book2 = Book.new 'matz', 'Ruby in a Nutshell'
98
+ #
99
+ # reviews = {}
100
+ #
101
+ # reviews[book1] = 'Great reference!'
102
+ # reviews[book2] = 'Nice and compact!'
103
+ #
104
+ # reviews.length #=> 1
105
+ #
106
+ # See also Object#hash and Object#eql?
107
+ #
108
+ class Hash[unchecked out K, unchecked out V] < Object
109
+ include Enumerable[[K, V], Hash[K, V]]
110
+
111
+ # Creates a new hash populated with the given objects.
112
+ #
113
+ # Similar to the literal `{ *key* => *value*, ... }`. In the first form, keys
114
+ # and values occur in pairs, so there must be an even number of arguments.
115
+ #
116
+ # The second and third form take a single argument which is either an array of
117
+ # key-value pairs or an object convertible to a hash.
118
+ #
119
+ # Hash["a", 100, "b", 200] #=> {"a"=>100, "b"=>200}
120
+ # Hash[ [ ["a", 100], ["b", 200] ] ] #=> {"a"=>100, "b"=>200}
121
+ # Hash["a" => 100, "b" => 200] #=> {"a"=>100, "b"=>200}
122
+ #
123
+ def self.[]: [U, V] (_ToHash[U, V]) -> ::Hash[U, V]
124
+ | [U, V] (Array[[ U, V ]]) -> ::Hash[U, V]
125
+ | (*untyped) -> ::Hash[untyped, untyped]
126
+
127
+ # Try to convert *obj* into a hash, using to_hash method. Returns converted hash
128
+ # or nil if *obj* cannot be converted for any reason.
129
+ #
130
+ # Hash.try_convert({1=>2}) # => {1=>2}
131
+ # Hash.try_convert("1=>2") # => nil
132
+ #
133
+ def self.try_convert: [U, V] (_ToHash[U, V]) -> ::Hash[U, V]
134
+ | (untyped) -> (::Hash[untyped, untyped] | nil)
135
+
136
+ public
137
+
138
+ # Returns `true` if *hash* is subset of *other*.
139
+ #
140
+ # h1 = {a:1, b:2}
141
+ # h2 = {a:1, b:2, c:3}
142
+ # h1 < h2 #=> true
143
+ # h2 < h1 #=> false
144
+ # h1 < h1 #=> false
145
+ #
146
+ def <: (::Hash[K, V]) -> bool
147
+
148
+ # Returns `true` if *hash* is subset of *other* or equals to *other*.
149
+ #
150
+ # h1 = {a:1, b:2}
151
+ # h2 = {a:1, b:2, c:3}
152
+ # h1 <= h2 #=> true
153
+ # h2 <= h1 #=> false
154
+ # h1 <= h1 #=> true
155
+ #
156
+ def <=: (::Hash[K, V]) -> bool
157
+
158
+ # Equality---Two hashes are equal if they each contain the same number of keys
159
+ # and if each key-value pair is equal to (according to Object#==) the
160
+ # corresponding elements in the other hash.
161
+ #
162
+ # h1 = { "a" => 1, "c" => 2 }
163
+ # h2 = { 7 => 35, "c" => 2, "a" => 1 }
164
+ # h3 = { "a" => 1, "c" => 2, 7 => 35 }
165
+ # h4 = { "a" => 1, "d" => 2, "f" => 35 }
166
+ # h1 == h2 #=> false
167
+ # h2 == h3 #=> true
168
+ # h3 == h4 #=> false
169
+ #
170
+ # The orders of each hashes are not compared.
171
+ #
172
+ # h1 = { "a" => 1, "c" => 2 }
173
+ # h2 = { "c" => 2, "a" => 1 }
174
+ # h1 == h2 #=> true
175
+ #
176
+ def ==: (untyped other) -> bool
177
+
178
+ # Returns `true` if *other* is subset of *hash*.
179
+ #
180
+ # h1 = {a:1, b:2}
181
+ # h2 = {a:1, b:2, c:3}
182
+ # h1 > h2 #=> false
183
+ # h2 > h1 #=> true
184
+ # h1 > h1 #=> false
185
+ #
186
+ def >: (::Hash[K, V]) -> bool
187
+
188
+ # Returns `true` if *other* is subset of *hash* or equals to *hash*.
189
+ #
190
+ # h1 = {a:1, b:2}
191
+ # h2 = {a:1, b:2, c:3}
192
+ # h1 >= h2 #=> false
193
+ # h2 >= h1 #=> true
194
+ # h1 >= h1 #=> true
195
+ #
196
+ def >=: (::Hash[K, V]) -> bool
197
+
198
+ # Element Reference---Retrieves the *value* object corresponding to the *key*
199
+ # object. If not found, returns the default value (see Hash::new for details).
200
+ #
201
+ # h = { "a" => 100, "b" => 200 }
202
+ # h["a"] #=> 100
203
+ # h["c"] #=> nil
204
+ #
205
+ def []: (K arg0) -> V
206
+
207
+ # ## Element Assignment
208
+ #
209
+ # Associates the value given by `value` with the key given by `key`.
210
+ #
211
+ # h = { "a" => 100, "b" => 200 }
212
+ # h["a"] = 9
213
+ # h["c"] = 4
214
+ # h #=> {"a"=>9, "b"=>200, "c"=>4}
215
+ # h.store("d", 42) #=> 42
216
+ # h #=> {"a"=>9, "b"=>200, "c"=>4, "d"=>42}
217
+ #
218
+ # `key` should not have its value changed while it is in use as a key (an
219
+ # `unfrozen String` passed as a key will be duplicated and frozen).
220
+ #
221
+ # a = "a"
222
+ # b = "b".freeze
223
+ # h = { a => 100, b => 200 }
224
+ # h.key(100).equal? a #=> false
225
+ # h.key(200).equal? b #=> true
226
+ #
227
+ def []=: (K arg0, V arg1) -> V
228
+
229
+ # See also Enumerable#any?
230
+ #
231
+ def any?: () -> bool
232
+ | (untyped pattern) -> bool
233
+ | () { (K, V) -> bool } -> bool
234
+
235
+ # Searches through the hash comparing *obj* with the key using `==`. Returns the
236
+ # key-value pair (two elements array) or `nil` if no match is found. See
237
+ # Array#assoc.
238
+ #
239
+ # h = {"colors" => ["red", "blue", "green"],
240
+ # "letters" => ["a", "b", "c" ]}
241
+ # h.assoc("letters") #=> ["letters", ["a", "b", "c"]]
242
+ # h.assoc("foo") #=> nil
243
+ #
244
+ def assoc: (K arg0) -> [K, V]?
245
+
246
+ # Removes all key-value pairs from *hsh*.
247
+ #
248
+ # h = { "a" => 100, "b" => 200 } #=> {"a"=>100, "b"=>200}
249
+ # h.clear #=> {}
250
+ #
251
+ def clear: () -> self
252
+
253
+ # Returns a new hash with the nil values/key pairs removed
254
+ #
255
+ # h = { a: 1, b: false, c: nil }
256
+ # h.compact #=> { a: 1, b: false }
257
+ # h #=> { a: 1, b: false, c: nil }
258
+ #
259
+ def compact: () -> self
260
+
261
+ # Removes all nil values from the hash. Returns nil if no changes were made,
262
+ # otherwise returns the hash.
263
+ #
264
+ # h = { a: 1, b: false, c: nil }
265
+ # h.compact! #=> { a: 1, b: false }
266
+ #
267
+ def compact!: () -> self?
268
+
269
+ # Makes *hsh* compare its keys by their identity, i.e. it will consider exact
270
+ # same objects as same keys.
271
+ #
272
+ # h1 = { "a" => 100, "b" => 200, :c => "c" }
273
+ # h1["a"] #=> 100
274
+ # h1.compare_by_identity
275
+ # h1.compare_by_identity? #=> true
276
+ # h1["a".dup] #=> nil # different objects.
277
+ # h1[:c] #=> "c" # same symbols are all same.
278
+ #
279
+ def compare_by_identity: () -> self
280
+
281
+ # Returns `true` if *hsh* will compare its keys by their identity. Also see
282
+ # Hash#compare_by_identity.
283
+ #
284
+ def compare_by_identity?: () -> bool
285
+
286
+ def deconstruct_keys: (Array[K] | nil) -> self
287
+
288
+ # Returns the default value, the value that would be returned by *[hsh](key)* if
289
+ # *key* did not exist in *hsh*. See also Hash::new and Hash#default=.
290
+ #
291
+ # h = Hash.new #=> {}
292
+ # h.default #=> nil
293
+ # h.default(2) #=> nil
294
+ #
295
+ # h = Hash.new("cat") #=> {}
296
+ # h.default #=> "cat"
297
+ # h.default(2) #=> "cat"
298
+ #
299
+ # h = Hash.new {|h,k| h[k] = k.to_i*10} #=> {}
300
+ # h.default #=> nil
301
+ # h.default(2) #=> 20
302
+ #
303
+ def default: (?K arg0) -> V?
304
+
305
+ # Sets the default value, the value returned for a key that does not exist in
306
+ # the hash. It is not possible to set the default to a Proc that will be
307
+ # executed on each key lookup.
308
+ #
309
+ # h = { "a" => 100, "b" => 200 }
310
+ # h.default = "Go fish"
311
+ # h["a"] #=> 100
312
+ # h["z"] #=> "Go fish"
313
+ # # This doesn't do what you might hope...
314
+ # h.default = proc do |hash, key|
315
+ # hash[key] = key + key
316
+ # end
317
+ # h[2] #=> #<Proc:0x401b3948@-:6>
318
+ # h["cat"] #=> #<Proc:0x401b3948@-:6>
319
+ #
320
+ def default=: (V arg0) -> V
321
+
322
+ # If Hash::new was invoked with a block, return that block, otherwise return
323
+ # `nil`.
324
+ #
325
+ # h = Hash.new {|h,k| h[k] = k*k } #=> {}
326
+ # p = h.default_proc #=> #<Proc:0x401b3d08@-:1>
327
+ # a = [] #=> []
328
+ # p.call(a, 2)
329
+ # a #=> [nil, nil, 4]
330
+ #
331
+ def default_proc: () -> (Proc | nil)
332
+
333
+ # Sets the default proc to be executed on each failed key lookup.
334
+ #
335
+ # h.default_proc = proc do |hash, key|
336
+ # hash[key] = key + key
337
+ # end
338
+ # h[2] #=> 4
339
+ # h["cat"] #=> "catcat"
340
+ #
341
+ def default_proc=: (Proc | _ToProc | nil) -> (Proc | _ToProc | nil)
342
+
343
+ # Deletes the key-value pair and returns the value from *hsh* whose key is equal
344
+ # to *key*. If the key is not found, it returns *nil*. If the optional code
345
+ # block is given and the key is not found, pass in the key and return the result
346
+ # of *block*.
347
+ #
348
+ # h = { "a" => 100, "b" => 200 }
349
+ # h.delete("a") #=> 100
350
+ # h.delete("z") #=> nil
351
+ # h.delete("z") { |el| "#{el} not found" } #=> "z not found"
352
+ #
353
+ def delete: (K arg0) -> V?
354
+ | [U] (K arg0) { (K arg0) -> U } -> (U | V)
355
+
356
+ # Deletes every key-value pair from *hsh* for which *block* evaluates to `true`.
357
+ #
358
+ # If no block is given, an enumerator is returned instead.
359
+ #
360
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
361
+ # h.delete_if {|key, value| key >= "b" } #=> {"a"=>100}
362
+ #
363
+ def delete_if: () { (K arg0, V arg1) -> bool } -> self
364
+ | () -> ::Enumerator[[ K, V ], self]
365
+
366
+ # Extracts the nested value specified by the sequence of *key* objects by
367
+ # calling `dig` at each step, returning `nil` if any intermediate step is `nil`.
368
+ #
369
+ # h = { foo: {bar: {baz: 1}}}
370
+ #
371
+ # h.dig(:foo, :bar, :baz) #=> 1
372
+ # h.dig(:foo, :zot, :xyz) #=> nil
373
+ #
374
+ # g = { foo: [10, 11, 12] }
375
+ # g.dig(:foo, 1) #=> 11
376
+ # g.dig(:foo, 1, 0) #=> TypeError: Integer does not have #dig method
377
+ # g.dig(:foo, :bar) #=> TypeError: no implicit conversion of Symbol into Integer
378
+ #
379
+ def dig: (*untyped) -> untyped
380
+
381
+ # Calls *block* once for each key in *hsh*, passing the key-value pair as
382
+ # parameters.
383
+ #
384
+ # If no block is given, an enumerator is returned instead.
385
+ #
386
+ # h = { "a" => 100, "b" => 200 }
387
+ # h.each {|key, value| puts "#{key} is #{value}" }
388
+ #
389
+ # *produces:*
390
+ #
391
+ # a is 100
392
+ # b is 200
393
+ #
394
+ def each: () { ([ K, V ] arg0) -> untyped } -> self
395
+ | () -> ::Enumerator[[ K, V ], self]
396
+
397
+ # Calls *block* once for each key in *hsh*, passing the key as a parameter.
398
+ #
399
+ # If no block is given, an enumerator is returned instead.
400
+ #
401
+ # h = { "a" => 100, "b" => 200 }
402
+ # h.each_key {|key| puts key }
403
+ #
404
+ # *produces:*
405
+ #
406
+ # a
407
+ # b
408
+ #
409
+ def each_key: () { (K arg0) -> untyped } -> ::Hash[K, V]
410
+ | () -> ::Enumerator[K, self]
411
+
412
+ # Calls *block* once for each key in *hsh*, passing the key-value pair as
413
+ # parameters.
414
+ #
415
+ # If no block is given, an enumerator is returned instead.
416
+ #
417
+ # h = { "a" => 100, "b" => 200 }
418
+ # h.each {|key, value| puts "#{key} is #{value}" }
419
+ #
420
+ # *produces:*
421
+ #
422
+ # a is 100
423
+ # b is 200
424
+ #
425
+ alias each_pair each
426
+
427
+ # Calls *block* once for each key in *hsh*, passing the value as a parameter.
428
+ #
429
+ # If no block is given, an enumerator is returned instead.
430
+ #
431
+ # h = { "a" => 100, "b" => 200 }
432
+ # h.each_value {|value| puts value }
433
+ #
434
+ # *produces:*
435
+ #
436
+ # 100
437
+ # 200
438
+ #
439
+ def each_value: () { (V arg0) -> untyped } -> self
440
+ | () -> ::Enumerator[V, self]
441
+
442
+ # Returns `true` if *hsh* contains no key-value pairs.
443
+ #
444
+ # {}.empty? #=> true
445
+ #
446
+ def empty?: () -> bool
447
+
448
+ # Returns `true` if *hash* and *other* are both hashes with the same content.
449
+ # The orders of each hashes are not compared.
450
+ #
451
+ def eql?: (untyped) -> bool
452
+
453
+ # Returns a value from the hash for the given key. If the key can't be found,
454
+ # there are several options: With no other arguments, it will raise a KeyError
455
+ # exception; if *default* is given, then that will be returned; if the optional
456
+ # code block is specified, then that will be run and its result returned.
457
+ #
458
+ # h = { "a" => 100, "b" => 200 }
459
+ # h.fetch("a") #=> 100
460
+ # h.fetch("z", "go fish") #=> "go fish"
461
+ # h.fetch("z") { |el| "go fish, #{el}"} #=> "go fish, z"
462
+ #
463
+ # The following example shows that an exception is raised if the key is not
464
+ # found and a default value is not supplied.
465
+ #
466
+ # h = { "a" => 100, "b" => 200 }
467
+ # h.fetch("z")
468
+ #
469
+ # *produces:*
470
+ #
471
+ # prog.rb:2:in `fetch': key not found (KeyError)
472
+ # from prog.rb:2
473
+ #
474
+ def fetch: (K arg0) -> V
475
+ | [X] (K arg0, X arg1) -> (V | X)
476
+ | [X] (K arg0) { (K arg0) -> X } -> (V | X)
477
+
478
+ # Returns an array containing the values associated with the given keys but also
479
+ # raises KeyError when one of keys can't be found. Also see Hash#values_at and
480
+ # Hash#fetch.
481
+ #
482
+ # h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
483
+ #
484
+ # h.fetch_values("cow", "cat") #=> ["bovine", "feline"]
485
+ # h.fetch_values("cow", "bird") # raises KeyError
486
+ # h.fetch_values("cow", "bird") { |k| k.upcase } #=> ["bovine", "BIRD"]
487
+ #
488
+ def fetch_values: (*K) -> Array[V]
489
+ | [X] (*K) { (K) -> X } -> (V | X)
490
+
491
+ # Returns a new hash consisting of entries for which the block returns true.
492
+ #
493
+ # If no block is given, an enumerator is returned instead.
494
+ #
495
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
496
+ # h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300}
497
+ # h.select {|k,v| v < 200} #=> {"a" => 100}
498
+ #
499
+ # Hash#filter is an alias for Hash#select.
500
+ #
501
+ def filter: () { (K arg0, V arg1) -> bool } -> self
502
+ | () -> ::Enumerator[[ K, V ], self]
503
+
504
+ # Equivalent to Hash#keep_if, but returns `nil` if no changes were made.
505
+ #
506
+ # Hash#filter! is an alias for Hash#select!.
507
+ #
508
+ def filter!: () { (K arg0, V arg1) -> bool } -> self?
509
+ | () -> ::Enumerator[[ K, V ], self?]
510
+
511
+ # Returns a new array that is a one-dimensional flattening of this hash. That
512
+ # is, for every key or value that is an array, extract its elements into the new
513
+ # array. Unlike Array#flatten, this method does not flatten recursively by
514
+ # default. The optional *level* argument determines the level of recursion to
515
+ # flatten.
516
+ #
517
+ # a = {1=> "one", 2 => [2,"two"], 3 => "three"}
518
+ # a.flatten # => [1, "one", 2, [2, "two"], 3, "three"]
519
+ # a.flatten(2) # => [1, "one", 2, 2, "two", 3, "three"]
520
+ #
521
+ def flatten: () -> ::Array[K | V]
522
+ | (1 level) -> ::Array[K | V]
523
+ | (Integer level) -> Array[untyped]
524
+
525
+ # Returns `true` if the given key is present in *hsh*.
526
+ #
527
+ # h = { "a" => 100, "b" => 200 }
528
+ # h.has_key?("a") #=> true
529
+ # h.has_key?("z") #=> false
530
+ #
531
+ # Note that #include? and #member? do not test member equality using `==` as do
532
+ # other Enumerables.
533
+ #
534
+ # See also Enumerable#include?
535
+ #
536
+ def has_key?: (K arg0) -> bool
537
+
538
+ # Returns `true` if the given value is present for some key in *hsh*.
539
+ #
540
+ # h = { "a" => 100, "b" => 200 }
541
+ # h.value?(100) #=> true
542
+ # h.value?(999) #=> false
543
+ #
544
+ def has_value?: (V arg0) -> bool
545
+
546
+ # Compute a hash-code for this hash. Two hashes with the same content will have
547
+ # the same hash code (and will compare using `eql?`).
548
+ #
549
+ # See also Object#hash.
550
+ #
551
+ def hash: () -> Integer
552
+
553
+ # Returns `true` if the given key is present in *hsh*.
554
+ #
555
+ # h = { "a" => 100, "b" => 200 }
556
+ # h.has_key?("a") #=> true
557
+ # h.has_key?("z") #=> false
558
+ #
559
+ # Note that #include? and #member? do not test member equality using `==` as do
560
+ # other Enumerables.
561
+ #
562
+ # See also Enumerable#include?
563
+ #
564
+ alias include? has_key?
565
+
566
+ def index: (V) -> K?
567
+
568
+ # Return the contents of this hash as a string.
569
+ #
570
+ # h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
571
+ # h.to_s #=> "{\"c\"=>300, \"a\"=>100, \"d\"=>400}"
572
+ #
573
+ def inspect: () -> String
574
+
575
+ # Returns a new hash created by using *hsh*'s values as keys, and the keys as
576
+ # values. If a key with the same value already exists in the *hsh*, then the
577
+ # last one defined will be used, the earlier value(s) will be discarded.
578
+ #
579
+ # h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 }
580
+ # h.invert #=> {0=>"a", 100=>"m", 200=>"d", 300=>"y"}
581
+ #
582
+ # If there is no key with the same value, Hash#invert is involutive.
583
+ #
584
+ # h = { a: 1, b: 3, c: 4 }
585
+ # h.invert.invert == h #=> true
586
+ #
587
+ # The condition, no key with the same value, can be tested by comparing the size
588
+ # of inverted hash.
589
+ #
590
+ # # no key with the same value
591
+ # h = { a: 1, b: 3, c: 4 }
592
+ # h.size == h.invert.size #=> true
593
+ #
594
+ # # two (or more) keys has the same value
595
+ # h = { a: 1, b: 3, c: 1 }
596
+ # h.size == h.invert.size #=> false
597
+ #
598
+ def invert: () -> ::Hash[V, K]
599
+
600
+ # Deletes every key-value pair from *hsh* for which *block* evaluates to
601
+ # `false`.
602
+ #
603
+ # If no block is given, an enumerator is returned instead.
604
+ #
605
+ # See also Hash#select!.
606
+ #
607
+ def keep_if: () { (K, V) -> bool } -> self
608
+ | () -> ::Enumerator[[ K, V ], self]
609
+
610
+ # Returns the key of an occurrence of a given value. If the value is not found,
611
+ # returns `nil`.
612
+ #
613
+ # h = { "a" => 100, "b" => 200, "c" => 300, "d" => 300 }
614
+ # h.key(200) #=> "b"
615
+ # h.key(300) #=> "c"
616
+ # h.key(999) #=> nil
617
+ #
618
+ alias key index
619
+
620
+ # Returns `true` if the given key is present in *hsh*.
621
+ #
622
+ # h = { "a" => 100, "b" => 200 }
623
+ # h.has_key?("a") #=> true
624
+ # h.has_key?("z") #=> false
625
+ #
626
+ # Note that #include? and #member? do not test member equality using `==` as do
627
+ # other Enumerables.
628
+ #
629
+ # See also Enumerable#include?
630
+ #
631
+ alias key? has_key?
632
+
633
+ # Returns a new array populated with the keys from this hash. See also
634
+ # Hash#values.
635
+ #
636
+ # h = { "a" => 100, "b" => 200, "c" => 300, "d" => 400 }
637
+ # h.keys #=> ["a", "b", "c", "d"]
638
+ #
639
+ def keys: () -> ::Array[K]
640
+
641
+ # Returns the number of key-value pairs in the hash.
642
+ #
643
+ # h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 }
644
+ # h.size #=> 4
645
+ # h.delete("a") #=> 200
646
+ # h.size #=> 3
647
+ # h.length #=> 3
648
+ #
649
+ # Hash#length is an alias for Hash#size.
650
+ #
651
+ def length: () -> Integer
652
+
653
+ # Returns `true` if the given key is present in *hsh*.
654
+ #
655
+ # h = { "a" => 100, "b" => 200 }
656
+ # h.has_key?("a") #=> true
657
+ # h.has_key?("z") #=> false
658
+ #
659
+ # Note that #include? and #member? do not test member equality using `==` as do
660
+ # other Enumerables.
661
+ #
662
+ # See also Enumerable#include?
663
+ #
664
+ alias member? has_key?
665
+
666
+ # Returns a new hash that combines the contents of the receiver and the contents
667
+ # of the given hashes.
668
+ #
669
+ # If no block is given, entries with duplicate keys are overwritten with the
670
+ # values from each `other_hash` successively, otherwise the value for each
671
+ # duplicate key is determined by calling the block with the key, its value in
672
+ # the receiver and its value in each `other_hash`.
673
+ #
674
+ # When called without any argument, returns a copy of the receiver.
675
+ #
676
+ # h1 = { "a" => 100, "b" => 200 }
677
+ # h2 = { "b" => 246, "c" => 300 }
678
+ # h3 = { "b" => 357, "d" => 400 }
679
+ # h1.merge #=> {"a"=>100, "b"=>200}
680
+ # h1.merge(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
681
+ # h1.merge(h2, h3) #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
682
+ # h1.merge(h2) {|key, oldval, newval| newval - oldval}
683
+ # #=> {"a"=>100, "b"=>46, "c"=>300}
684
+ # h1.merge(h2, h3) {|key, oldval, newval| newval - oldval}
685
+ # #=> {"a"=>100, "b"=>311, "c"=>300, "d"=>400}
686
+ # h1 #=> {"a"=>100, "b"=>200}
687
+ #
688
+ def merge: [A, B] (*::Hash[A, B] other_hashes) -> ::Hash[A | K, B | V]
689
+ | [A, B, C] (*::Hash[A, B] other_hashes) { (K key, V oldval, B newval) -> (C) } -> ::Hash[A | K, B | V | C]
690
+
691
+ # Adds the contents of the given hashes to the receiver.
692
+ #
693
+ # If no block is given, entries with duplicate keys are overwritten with the
694
+ # values from each `other_hash` successively, otherwise the value for each
695
+ # duplicate key is determined by calling the block with the key, its value in
696
+ # the receiver and its value in each `other_hash`.
697
+ #
698
+ # h1 = { "a" => 100, "b" => 200 }
699
+ # h1.merge! #=> {"a"=>100, "b"=>200}
700
+ # h1 #=> {"a"=>100, "b"=>200}
701
+ #
702
+ # h1 = { "a" => 100, "b" => 200 }
703
+ # h2 = { "b" => 246, "c" => 300 }
704
+ # h1.merge!(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
705
+ # h1 #=> {"a"=>100, "b"=>246, "c"=>300}
706
+ #
707
+ # h1 = { "a" => 100, "b" => 200 }
708
+ # h2 = { "b" => 246, "c" => 300 }
709
+ # h3 = { "b" => 357, "d" => 400 }
710
+ # h1.merge!(h2, h3)
711
+ # #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
712
+ # h1 #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
713
+ #
714
+ # h1 = { "a" => 100, "b" => 200 }
715
+ # h2 = { "b" => 246, "c" => 300 }
716
+ # h3 = { "b" => 357, "d" => 400 }
717
+ # h1.merge!(h2, h3) {|key, v1, v2| v1 }
718
+ # #=> {"a"=>100, "b"=>200, "c"=>300, "d"=>400}
719
+ # h1 #=> {"a"=>100, "b"=>200, "c"=>300, "d"=>400}
720
+ #
721
+ # Hash#update is an alias for Hash#merge!.
722
+ #
723
+ def merge!: [A, B] (*::Hash[A, B] other_hashes) -> ::Hash[A | K, B | V]
724
+ | [A, B, C] (*::Hash[A, B] other_hashes) { (K key, V oldval, B newval) -> (C) } -> ::Hash[A | K, B | V | C]
725
+
726
+ # Searches through the hash comparing *obj* with the value using `==`. Returns
727
+ # the first key-value pair (two-element array) that matches. See also
728
+ # Array#rassoc.
729
+ #
730
+ # a = {1=> "one", 2 => "two", 3 => "three", "ii" => "two"}
731
+ # a.rassoc("two") #=> [2, "two"]
732
+ # a.rassoc("four") #=> nil
733
+ #
734
+ def rassoc: (V) -> [K, V]?
735
+
736
+ # Rebuilds the hash based on the current hash values for each key. If values of
737
+ # key objects have changed since they were inserted, this method will reindex
738
+ # *hsh*. If Hash#rehash is called while an iterator is traversing the hash, a
739
+ # RuntimeError will be raised in the iterator.
740
+ #
741
+ # a = [ "a", "b" ]
742
+ # c = [ "c", "d" ]
743
+ # h = { a => 100, c => 300 }
744
+ # h[a] #=> 100
745
+ # a[0] = "z"
746
+ # h[a] #=> nil
747
+ # h.rehash #=> {["z", "b"]=>100, ["c", "d"]=>300}
748
+ # h[a] #=> 100
749
+ #
750
+ def rehash: () -> self
751
+
752
+ # Returns a new hash consisting of entries for which the block returns false.
753
+ #
754
+ # If no block is given, an enumerator is returned instead.
755
+ #
756
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
757
+ # h.reject {|k,v| k < "b"} #=> {"b" => 200, "c" => 300}
758
+ # h.reject {|k,v| v > 100} #=> {"a" => 100}
759
+ #
760
+ def reject: () -> ::Enumerator[[ K, V ], self]
761
+ | () { (K arg0, V arg1) -> bool } -> self
762
+
763
+ # Equivalent to Hash#delete_if, but returns `nil` if no changes were made.
764
+ #
765
+ def reject!: () -> ::Enumerator[[ K, V ], self?]
766
+ | () { (K arg0, V arg1) -> bool } -> self?
767
+
768
+ # Replaces the contents of *hsh* with the contents of *other_hash*.
769
+ #
770
+ # h = { "a" => 100, "b" => 200 }
771
+ # h.replace({ "c" => 300, "d" => 400 }) #=> {"c"=>300, "d"=>400}
772
+ #
773
+ def replace: [A, B] (Hash[A, B] | _ToHash[A, B]) -> Hash[A, B]
774
+
775
+ # Returns a new hash consisting of entries for which the block returns true.
776
+ #
777
+ # If no block is given, an enumerator is returned instead.
778
+ #
779
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
780
+ # h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300}
781
+ # h.select {|k,v| v < 200} #=> {"a" => 100}
782
+ #
783
+ # Hash#filter is an alias for Hash#select.
784
+ #
785
+ alias select filter
786
+
787
+ # Equivalent to Hash#keep_if, but returns `nil` if no changes were made.
788
+ #
789
+ # Hash#filter! is an alias for Hash#select!.
790
+ #
791
+ alias select! filter!
792
+
793
+ # Removes a key-value pair from *hsh* and returns it as the two-item array `[`
794
+ # *key, value* `]`, or the hash's default value if the hash is empty.
795
+ #
796
+ # h = { 1 => "a", 2 => "b", 3 => "c" }
797
+ # h.shift #=> [1, "a"]
798
+ # h #=> {2=>"b", 3=>"c"}
799
+ #
800
+ def shift: () -> [ K, V ]?
801
+
802
+ # Returns the number of key-value pairs in the hash.
803
+ #
804
+ # h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 }
805
+ # h.size #=> 4
806
+ # h.delete("a") #=> 200
807
+ # h.size #=> 3
808
+ # h.length #=> 3
809
+ #
810
+ # Hash#length is an alias for Hash#size.
811
+ #
812
+ alias size length
813
+
814
+ # Returns a hash containing only the given keys and their values.
815
+ #
816
+ # h = { a: 100, b: 200, c: 300 }
817
+ # h.slice(:a) #=> {:a=>100}
818
+ # h.slice(:b, :c, :d) #=> {:b=>200, :c=>300}
819
+ #
820
+ def slice: (*K) -> self
821
+
822
+ # ## Element Assignment
823
+ #
824
+ # Associates the value given by `value` with the key given by `key`.
825
+ #
826
+ # h = { "a" => 100, "b" => 200 }
827
+ # h["a"] = 9
828
+ # h["c"] = 4
829
+ # h #=> {"a"=>9, "b"=>200, "c"=>4}
830
+ # h.store("d", 42) #=> 42
831
+ # h #=> {"a"=>9, "b"=>200, "c"=>4, "d"=>42}
832
+ #
833
+ # `key` should not have its value changed while it is in use as a key (an
834
+ # `unfrozen String` passed as a key will be duplicated and frozen).
835
+ #
836
+ # a = "a"
837
+ # b = "b".freeze
838
+ # h = { a => 100, b => 200 }
839
+ # h.key(100).equal? a #=> false
840
+ # h.key(200).equal? b #=> true
841
+ #
842
+ alias store []=
843
+
844
+ # Converts *hsh* to a nested array of `[` *key, value* `]` arrays.
845
+ #
846
+ # h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
847
+ # h.to_a #=> [["c", 300], ["a", 100], ["d", 400]]
848
+ #
849
+ def to_a: () -> ::Array[[ K, V ]]
850
+
851
+ # Returns `self`. If called on a subclass of Hash, converts the receiver to a
852
+ # Hash object.
853
+ #
854
+ # If a block is given, the results of the block on each pair of the receiver
855
+ # will be used as pairs.
856
+ #
857
+ def to_h: () -> Hash[K, V]
858
+ | [A, B] () { (K, V) -> [ A, B ] } -> Hash[A, B]
859
+
860
+ # Returns `self`.
861
+ #
862
+ def to_hash: () -> ::Hash[K, V]
863
+
864
+ # Returns a Proc which maps keys to values.
865
+ #
866
+ # h = {a:1, b:2}
867
+ # hp = h.to_proc
868
+ # hp.call(:a) #=> 1
869
+ # hp.call(:b) #=> 2
870
+ # hp.call(:c) #=> nil
871
+ # [:a, :b, :c].map(&h) #=> [1, 2, nil]
872
+ #
873
+ def to_proc: () -> ^(K) -> V?
874
+
875
+ alias to_s inspect
876
+
877
+ # Returns a new hash with the results of running the block once for every key.
878
+ # This method does not change the values.
879
+ #
880
+ # h = { a: 1, b: 2, c: 3 }
881
+ # h.transform_keys {|k| k.to_s } #=> { "a" => 1, "b" => 2, "c" => 3 }
882
+ # h.transform_keys(&:to_s) #=> { "a" => 1, "b" => 2, "c" => 3 }
883
+ # h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
884
+ # #=> { "a.0" => 1, "b.1" => 2, "c.2" => 3 }
885
+ #
886
+ # If no block is given, an enumerator is returned instead.
887
+ #
888
+ def transform_keys: () -> Enumerator[K, Hash[untyped, V]]
889
+ | [A] () { (K) -> A } -> Hash[A, V]
890
+
891
+ # Invokes the given block once for each key in *hsh*, replacing it with the new
892
+ # key returned by the block, and then returns *hsh*. This method does not change
893
+ # the values.
894
+ #
895
+ # h = { a: 1, b: 2, c: 3 }
896
+ # h.transform_keys! {|k| k.to_s } #=> { "a" => 1, "b" => 2, "c" => 3 }
897
+ # h.transform_keys!(&:to_sym) #=> { a: 1, b: 2, c: 3 }
898
+ # h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
899
+ # #=> { "a.0" => 1, "b.1" => 2, "c.2" => 3 }
900
+ #
901
+ # If no block is given, an enumerator is returned instead.
902
+ #
903
+ def transform_keys!: () -> Enumerator[K, Hash[untyped, V]]
904
+ | () { (K) -> K } -> Hash[K, V]
905
+
906
+ # Returns a new hash with the results of running the block once for every value.
907
+ # This method does not change the keys.
908
+ #
909
+ # h = { a: 1, b: 2, c: 3 }
910
+ # h.transform_values {|v| v * v + 1 } #=> { a: 2, b: 5, c: 10 }
911
+ # h.transform_values(&:to_s) #=> { a: "1", b: "2", c: "3" }
912
+ # h.transform_values.with_index {|v, i| "#{v}.#{i}" }
913
+ # #=> { a: "1.0", b: "2.1", c: "3.2" }
914
+ #
915
+ # If no block is given, an enumerator is returned instead.
916
+ #
917
+ def transform_values: () -> Enumerator[K, Hash[K, untyped]]
918
+ | [A] () { (V) -> A } -> Hash[K, A]
919
+
920
+ # Invokes the given block once for each value in *hsh*, replacing it with the
921
+ # new value returned by the block, and then returns *hsh*. This method does not
922
+ # change the keys.
923
+ #
924
+ # h = { a: 1, b: 2, c: 3 }
925
+ # h.transform_values! {|v| v * v + 1 } #=> { a: 2, b: 5, c: 10 }
926
+ # h.transform_values!(&:to_s) #=> { a: "2", b: "5", c: "10" }
927
+ # h.transform_values!.with_index {|v, i| "#{v}.#{i}" }
928
+ # #=> { a: "2.0", b: "5.1", c: "10.2" }
929
+ #
930
+ # If no block is given, an enumerator is returned instead.
931
+ #
932
+ def transform_values!: () -> Enumerator[K, Hash[K, untyped]]
933
+ | () { (V) -> V } -> Hash[K, V]
934
+
935
+ # Adds the contents of the given hashes to the receiver.
936
+ #
937
+ # If no block is given, entries with duplicate keys are overwritten with the
938
+ # values from each `other_hash` successively, otherwise the value for each
939
+ # duplicate key is determined by calling the block with the key, its value in
940
+ # the receiver and its value in each `other_hash`.
941
+ #
942
+ # h1 = { "a" => 100, "b" => 200 }
943
+ # h1.merge! #=> {"a"=>100, "b"=>200}
944
+ # h1 #=> {"a"=>100, "b"=>200}
945
+ #
946
+ # h1 = { "a" => 100, "b" => 200 }
947
+ # h2 = { "b" => 246, "c" => 300 }
948
+ # h1.merge!(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
949
+ # h1 #=> {"a"=>100, "b"=>246, "c"=>300}
950
+ #
951
+ # h1 = { "a" => 100, "b" => 200 }
952
+ # h2 = { "b" => 246, "c" => 300 }
953
+ # h3 = { "b" => 357, "d" => 400 }
954
+ # h1.merge!(h2, h3)
955
+ # #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
956
+ # h1 #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
957
+ #
958
+ # h1 = { "a" => 100, "b" => 200 }
959
+ # h2 = { "b" => 246, "c" => 300 }
960
+ # h3 = { "b" => 357, "d" => 400 }
961
+ # h1.merge!(h2, h3) {|key, v1, v2| v1 }
962
+ # #=> {"a"=>100, "b"=>200, "c"=>300, "d"=>400}
963
+ # h1 #=> {"a"=>100, "b"=>200, "c"=>300, "d"=>400}
964
+ #
965
+ # Hash#update is an alias for Hash#merge!.
966
+ #
967
+ alias update merge!
968
+
969
+ # Returns `true` if the given value is present for some key in *hsh*.
970
+ #
971
+ # h = { "a" => 100, "b" => 200 }
972
+ # h.value?(100) #=> true
973
+ # h.value?(999) #=> false
974
+ #
975
+ alias value? has_value?
976
+
977
+ # Returns a new array populated with the values from *hsh*. See also Hash#keys.
978
+ #
979
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
980
+ # h.values #=> [100, 200, 300]
981
+ #
982
+ def values: () -> ::Array[V]
983
+
984
+ # Return an array containing the values associated with the given keys. Also see
985
+ # Hash.select.
986
+ #
987
+ # h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
988
+ # h.values_at("cow", "cat") #=> ["bovine", "feline"]
989
+ #
990
+ def values_at: (*K arg0) -> ::Array[V?]
991
+
992
+ private
993
+
994
+ # Returns a new, empty hash. If this hash is subsequently accessed by a key that
995
+ # doesn't correspond to a hash entry, the value returned depends on the style of
996
+ # `new` used to create the hash. In the first form, the access returns `nil`. If
997
+ # *obj* is specified, this single object will be used for all *default values*.
998
+ # If a block is specified, it will be called with the hash object and the key,
999
+ # and should return the default value. It is the block's responsibility to store
1000
+ # the value in the hash if required.
1001
+ #
1002
+ # h = Hash.new("Go Fish")
1003
+ # h["a"] = 100
1004
+ # h["b"] = 200
1005
+ # h["a"] #=> 100
1006
+ # h["c"] #=> "Go Fish"
1007
+ # # The following alters the single default object
1008
+ # h["c"].upcase! #=> "GO FISH"
1009
+ # h["d"] #=> "GO FISH"
1010
+ # h.keys #=> ["a", "b"]
1011
+ #
1012
+ # # While this creates a new default object each time
1013
+ # h = Hash.new { |hash, key| hash[key] = "Go Fish: #{key}" }
1014
+ # h["c"] #=> "Go Fish: c"
1015
+ # h["c"].upcase! #=> "GO FISH: C"
1016
+ # h["d"] #=> "Go Fish: d"
1017
+ # h.keys #=> ["c", "d"]
1018
+ #
1019
+ incompatible def initialize: () -> void
1020
+ | (untyped default) -> void
1021
+ | [A, B] () { (Hash[A, B] hash, A key) -> B } -> void
1022
+
1023
+ # Replaces the contents of *hsh* with the contents of *other_hash*.
1024
+ #
1025
+ # h = { "a" => 100, "b" => 200 }
1026
+ # h.replace({ "c" => 300, "d" => 400 }) #=> {"c"=>300, "d"=>400}
1027
+ #
1028
+ def initialize_copy: (self object) -> self
1029
+ end