rbs 3.6.1 → 3.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -2
  3. data/.github/workflows/dependabot.yml +1 -1
  4. data/.github/workflows/ruby.yml +34 -10
  5. data/.github/workflows/windows.yml +20 -3
  6. data/.gitignore +1 -0
  7. data/.rubocop.yml +26 -1
  8. data/CHANGELOG.md +241 -0
  9. data/Rakefile +54 -4
  10. data/config.yml +317 -0
  11. data/core/array.rbs +1756 -1591
  12. data/core/basic_object.rbs +38 -35
  13. data/core/comparable.rbs +1 -1
  14. data/core/complex.rbs +166 -94
  15. data/core/data.rbs +2 -2
  16. data/core/dir.rbs +2 -18
  17. data/core/encoding.rbs +12 -32
  18. data/core/enumerable.rbs +270 -266
  19. data/core/enumerator.rbs +14 -4
  20. data/core/env.rbs +1 -1
  21. data/core/errno.rbs +33 -16
  22. data/core/errors.rbs +6 -2
  23. data/core/exception.rbs +342 -167
  24. data/core/fiber.rbs +3 -2
  25. data/core/file.rbs +26 -75
  26. data/core/float.rbs +125 -72
  27. data/core/gc.rbs +158 -42
  28. data/core/hash.rbs +122 -143
  29. data/core/integer.rbs +79 -50
  30. data/core/io/buffer.rbs +49 -43
  31. data/core/io.rbs +108 -151
  32. data/core/kernel.rbs +341 -209
  33. data/core/match_data.rbs +76 -2
  34. data/core/math.rbs +0 -36
  35. data/core/method.rbs +2 -2
  36. data/core/module.rbs +32 -27
  37. data/core/nil_class.rbs +2 -2
  38. data/core/numeric.rbs +101 -104
  39. data/core/object.rbs +1 -5
  40. data/core/object_space/weak_key_map.rbs +3 -4
  41. data/core/object_space.rbs +3 -3
  42. data/core/proc.rbs +82 -14
  43. data/core/process.rbs +110 -58
  44. data/core/ractor.rbs +57 -4
  45. data/core/range.rbs +114 -87
  46. data/core/rational.rbs +0 -2
  47. data/core/rbs/unnamed/argf.rbs +237 -36
  48. data/core/rbs/unnamed/env_class.rbs +35 -53
  49. data/core/rbs/unnamed/random.rbs +1 -2
  50. data/core/regexp.rbs +10 -56
  51. data/core/ruby_vm.rbs +88 -9
  52. data/core/rubygems/config_file.rbs +3 -0
  53. data/core/rubygems/errors.rbs +3 -6
  54. data/core/rubygems/platform.rbs +0 -9
  55. data/core/rubygems/rubygems.rbs +3 -6
  56. data/core/rubygems/version.rbs +8 -8
  57. data/core/set.rbs +4 -16
  58. data/core/string.rbs +271 -264
  59. data/core/struct.rbs +6 -18
  60. data/core/symbol.rbs +14 -21
  61. data/core/thread.rbs +32 -35
  62. data/core/time.rbs +131 -50
  63. data/core/trace_point.rbs +124 -113
  64. data/core/true_class.rbs +0 -1
  65. data/core/unbound_method.rbs +1 -1
  66. data/core/warning.rbs +9 -2
  67. data/docs/architecture.md +1 -1
  68. data/docs/syntax.md +17 -10
  69. data/ext/rbs_extension/extconf.rb +11 -0
  70. data/ext/rbs_extension/location.c +61 -29
  71. data/ext/rbs_extension/location.h +4 -3
  72. data/ext/rbs_extension/main.c +23 -1
  73. data/ext/rbs_extension/parser.c +506 -517
  74. data/ext/rbs_extension/parserstate.c +109 -30
  75. data/ext/rbs_extension/parserstate.h +6 -4
  76. data/ext/rbs_extension/rbs_extension.h +1 -10
  77. data/{ext/rbs_extension → include/rbs}/constants.h +21 -19
  78. data/include/rbs/ruby_objs.h +72 -0
  79. data/include/rbs/util/rbs_constant_pool.h +219 -0
  80. data/include/rbs.h +7 -0
  81. data/lib/rbs/annotate/annotations.rb +3 -3
  82. data/lib/rbs/annotate/rdoc_source.rb +2 -2
  83. data/lib/rbs/ast/declarations.rb +9 -4
  84. data/lib/rbs/ast/directives.rb +10 -0
  85. data/lib/rbs/ast/members.rb +2 -0
  86. data/lib/rbs/ast/type_param.rb +2 -12
  87. data/lib/rbs/cli/diff.rb +3 -3
  88. data/lib/rbs/cli/validate.rb +2 -1
  89. data/lib/rbs/cli.rb +16 -16
  90. data/lib/rbs/collection/config/lockfile_generator.rb +58 -8
  91. data/lib/rbs/collection/config.rb +5 -3
  92. data/lib/rbs/collection/sources/rubygems.rb +1 -1
  93. data/lib/rbs/collection.rb +1 -0
  94. data/lib/rbs/definition.rb +51 -34
  95. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -3
  96. data/lib/rbs/definition_builder.rb +83 -24
  97. data/lib/rbs/environment.rb +33 -18
  98. data/lib/rbs/environment_loader.rb +6 -1
  99. data/lib/rbs/errors.rb +24 -0
  100. data/lib/rbs/locator.rb +2 -0
  101. data/lib/rbs/method_type.rb +2 -0
  102. data/lib/rbs/namespace.rb +1 -0
  103. data/lib/rbs/parser_aux.rb +40 -3
  104. data/lib/rbs/prototype/rb.rb +20 -12
  105. data/lib/rbs/prototype/rbi.rb +11 -6
  106. data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
  107. data/lib/rbs/prototype/runtime.rb +7 -5
  108. data/lib/rbs/subtractor.rb +3 -3
  109. data/lib/rbs/test/hook.rb +47 -42
  110. data/lib/rbs/test/type_check.rb +7 -5
  111. data/lib/rbs/type_name.rb +14 -9
  112. data/lib/rbs/types.rb +63 -14
  113. data/lib/rbs/unit_test/spy.rb +4 -2
  114. data/lib/rbs/unit_test/type_assertions.rb +19 -13
  115. data/lib/rbs/unit_test/with_aliases.rb +3 -1
  116. data/lib/rbs/validator.rb +7 -1
  117. data/lib/rbs/version.rb +1 -1
  118. data/lib/rbs/writer.rb +10 -5
  119. data/lib/rbs.rb +1 -0
  120. data/lib/rdoc_plugin/parser.rb +2 -2
  121. data/rbs.gemspec +6 -2
  122. data/sig/ancestor_graph.rbs +5 -5
  123. data/sig/annotate/rdoc_source.rbs +2 -0
  124. data/sig/cli.rbs +2 -0
  125. data/sig/collection/config/lockfile_generator.rbs +9 -1
  126. data/sig/declarations.rbs +10 -3
  127. data/sig/definition.rbs +80 -12
  128. data/sig/definition_builder.rbs +18 -4
  129. data/sig/directives.rbs +17 -1
  130. data/sig/environment.rbs +3 -1
  131. data/sig/errors.rbs +19 -0
  132. data/sig/namespace.rbs +2 -3
  133. data/sig/parser.rbs +5 -1
  134. data/sig/prototype/rb.rbs +1 -1
  135. data/sig/resolver/constant_resolver.rbs +2 -2
  136. data/sig/resolver/context.rbs +1 -1
  137. data/sig/subtractor.rbs +1 -1
  138. data/sig/test/type_check.rbs +2 -2
  139. data/sig/type_alias_dependency.rbs +2 -2
  140. data/sig/type_alias_regularity.rbs +6 -6
  141. data/sig/type_param.rbs +4 -4
  142. data/sig/typename.rbs +8 -5
  143. data/sig/types.rbs +1 -1
  144. data/sig/unit_test/spy.rbs +2 -0
  145. data/sig/unit_test/type_assertions.rbs +2 -0
  146. data/sig/use_map.rbs +1 -1
  147. data/sig/validator.rbs +6 -2
  148. data/sig/vendorer.rbs +1 -1
  149. data/sig/writer.rbs +1 -1
  150. data/{ext/rbs_extension → src}/constants.c +35 -36
  151. data/src/ruby_objs.c +799 -0
  152. data/src/util/rbs_constant_pool.c +342 -0
  153. data/stdlib/base64/0/base64.rbs +0 -9
  154. data/stdlib/benchmark/0/benchmark.rbs +11 -2
  155. data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
  156. data/stdlib/cgi/0/core.rbs +60 -3
  157. data/stdlib/cgi/0/manifest.yaml +1 -0
  158. data/stdlib/coverage/0/coverage.rbs +0 -3
  159. data/stdlib/csv/0/csv.rbs +18 -58
  160. data/stdlib/csv/0/manifest.yaml +1 -0
  161. data/stdlib/date/0/date.rbs +27 -42
  162. data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -6
  163. data/stdlib/digest/0/digest.rbs +25 -2
  164. data/stdlib/erb/0/erb.rbs +0 -1
  165. data/stdlib/etc/0/etc.rbs +51 -34
  166. data/stdlib/fileutils/0/fileutils.rbs +3 -44
  167. data/stdlib/io-console/0/io-console.rbs +69 -15
  168. data/stdlib/ipaddr/0/ipaddr.rbs +16 -4
  169. data/stdlib/json/0/json.rbs +107 -120
  170. data/stdlib/logger/0/log_device.rbs +1 -1
  171. data/stdlib/logger/0/logger.rbs +3 -18
  172. data/stdlib/minitest/0/kernel.rbs +2 -2
  173. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +4 -1
  174. data/stdlib/minitest/0/minitest/assertion.rbs +1 -0
  175. data/stdlib/minitest/0/minitest/assertions.rbs +58 -13
  176. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +7 -0
  177. data/stdlib/minitest/0/minitest/bench_spec.rbs +8 -8
  178. data/stdlib/minitest/0/minitest/benchmark.rbs +17 -16
  179. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  180. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  181. data/stdlib/minitest/0/minitest/mock.rbs +9 -5
  182. data/stdlib/minitest/0/minitest/parallel/executor.rbs +4 -0
  183. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +0 -1
  184. data/stdlib/minitest/0/minitest/pride_io.rbs +8 -0
  185. data/stdlib/minitest/0/minitest/pride_lol.rbs +2 -0
  186. data/stdlib/minitest/0/minitest/progress_reporter.rbs +1 -1
  187. data/stdlib/minitest/0/minitest/reportable.rbs +2 -0
  188. data/stdlib/minitest/0/minitest/runnable.rbs +33 -1
  189. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +1 -1
  190. data/stdlib/minitest/0/minitest/spec/dsl.rbs +10 -6
  191. data/stdlib/minitest/0/minitest/spec.rbs +1 -1
  192. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +5 -0
  193. data/stdlib/minitest/0/minitest/summary_reporter.rbs +0 -7
  194. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +1 -1
  195. data/stdlib/minitest/0/minitest/test.rbs +7 -14
  196. data/stdlib/minitest/0/minitest/unexpected_error.rbs +2 -0
  197. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  198. data/stdlib/minitest/0/minitest/unit.rbs +1 -2
  199. data/stdlib/minitest/0/minitest.rbs +41 -892
  200. data/stdlib/monitor/0/monitor.rbs +13 -4
  201. data/stdlib/net-http/0/net-http.rbs +42 -109
  202. data/stdlib/nkf/0/nkf.rbs +30 -0
  203. data/stdlib/objspace/0/objspace.rbs +1 -2
  204. data/stdlib/observable/0/observable.rbs +1 -1
  205. data/stdlib/open-uri/0/manifest.yaml +1 -0
  206. data/stdlib/open-uri/0/open-uri.rbs +52 -0
  207. data/stdlib/open3/0/open3.rbs +0 -8
  208. data/stdlib/openssl/0/manifest.yaml +1 -0
  209. data/stdlib/openssl/0/openssl.rbs +235 -143
  210. data/stdlib/optparse/0/optparse.rbs +58 -18
  211. data/stdlib/pathname/0/pathname.rbs +2 -8
  212. data/stdlib/pp/0/pp.rbs +3 -1
  213. data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
  214. data/stdlib/pstore/0/pstore.rbs +0 -6
  215. data/stdlib/psych/0/core_ext.rbs +12 -0
  216. data/stdlib/psych/0/psych.rbs +15 -4
  217. data/stdlib/pty/0/pty.rbs +46 -4
  218. data/stdlib/rdoc/0/code_object.rbs +0 -4
  219. data/stdlib/rdoc/0/markup.rbs +10 -12
  220. data/stdlib/rdoc/0/rdoc.rbs +13 -8
  221. data/stdlib/resolv/0/resolv.rbs +21 -12
  222. data/stdlib/ripper/0/ripper.rbs +0 -2
  223. data/stdlib/securerandom/0/securerandom.rbs +7 -2
  224. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  225. data/stdlib/singleton/0/singleton.rbs +0 -1
  226. data/stdlib/socket/0/addrinfo.rbs +1 -2
  227. data/stdlib/socket/0/basic_socket.rbs +0 -5
  228. data/stdlib/socket/0/socket.rbs +32 -27
  229. data/stdlib/socket/0/tcp_server.rbs +0 -3
  230. data/stdlib/socket/0/tcp_socket.rbs +36 -3
  231. data/stdlib/socket/0/udp_socket.rbs +0 -1
  232. data/stdlib/socket/0/unix_server.rbs +0 -3
  233. data/stdlib/socket/0/unix_socket.rbs +4 -2
  234. data/{core/string_io.rbs → stdlib/stringio/0/stringio.rbs} +1 -1
  235. data/stdlib/strscan/0/string_scanner.rbs +1265 -422
  236. data/stdlib/tempfile/0/tempfile.rbs +135 -28
  237. data/stdlib/time/0/time.rbs +48 -35
  238. data/stdlib/timeout/0/timeout.rbs +11 -8
  239. data/stdlib/tmpdir/0/tmpdir.rbs +10 -3
  240. data/stdlib/tsort/0/tsort.rbs +0 -4
  241. data/stdlib/uri/0/common.rbs +28 -30
  242. data/stdlib/uri/0/ftp.rbs +1 -1
  243. data/stdlib/uri/0/generic.rbs +22 -18
  244. data/stdlib/uri/0/http.rbs +2 -2
  245. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  246. data/stdlib/zlib/0/buf_error.rbs +1 -70
  247. data/stdlib/zlib/0/data_error.rbs +1 -70
  248. data/stdlib/zlib/0/deflate.rbs +8 -72
  249. data/stdlib/zlib/0/error.rbs +1 -70
  250. data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
  251. data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
  252. data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
  253. data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
  254. data/stdlib/zlib/0/gzip_file.rbs +1 -71
  255. data/stdlib/zlib/0/gzip_reader.rbs +3 -74
  256. data/stdlib/zlib/0/gzip_writer.rbs +1 -70
  257. data/stdlib/zlib/0/inflate.rbs +4 -71
  258. data/stdlib/zlib/0/mem_error.rbs +1 -70
  259. data/stdlib/zlib/0/need_dict.rbs +1 -70
  260. data/stdlib/zlib/0/stream_end.rbs +1 -70
  261. data/stdlib/zlib/0/stream_error.rbs +1 -70
  262. data/stdlib/zlib/0/version_error.rbs +1 -70
  263. data/stdlib/zlib/0/zlib.rbs +0 -2
  264. data/stdlib/zlib/0/zstream.rbs +4 -72
  265. metadata +17 -13
  266. data/ext/rbs_extension/ruby_objs.c +0 -602
  267. data/ext/rbs_extension/ruby_objs.h +0 -51
  268. data/stdlib/minitest/0/manifest.yaml +0 -2
data/core/hash.rbs CHANGED
@@ -1,19 +1,18 @@
1
1
  # <!-- rdoc-file=hash.c -->
2
- # A Hash maps each of its unique keys to a specific value.
2
+ # A `Hash` maps each of its unique keys to a specific value.
3
3
  #
4
- # A Hash has certain similarities to an Array, but:
4
+ # A `Hash` has certain similarities to an Array, but:
5
5
  # * An Array index is always an Integer.
6
- # * A Hash key can be (almost) any object.
6
+ # * A `Hash` key can be (almost) any object.
7
7
  #
8
+ # ### `Hash` Data Syntax
8
9
  #
9
- # ### Hash Data Syntax
10
- #
11
- # The older syntax for Hash data uses the "hash rocket," `=>`:
10
+ # The older syntax for `Hash` data uses the "hash rocket," `=>`:
12
11
  #
13
12
  # h = {:foo => 0, :bar => 1, :baz => 2}
14
13
  # h # => {:foo=>0, :bar=>1, :baz=>2}
15
14
  #
16
- # Alternatively, but only for a Hash key that's a Symbol, you can use a newer
15
+ # Alternatively, but only for a `Hash` key that's a Symbol, you can use a newer
17
16
  # JSON-style syntax, where each bareword becomes a Symbol:
18
17
  #
19
18
  # h = {foo: 0, bar: 1, baz: 2}
@@ -35,8 +34,8 @@
35
34
  # # Raises SyntaxError (syntax error, unexpected ':', expecting =>):
36
35
  # h = {0: 'zero'}
37
36
  #
38
- # Hash value can be omitted, meaning that value will be fetched from the context
39
- # by the name of the key:
37
+ # `Hash` value can be omitted, meaning that value will be fetched from the
38
+ # context by the name of the key:
40
39
  #
41
40
  # x = 0
42
41
  # y = 100
@@ -45,24 +44,24 @@
45
44
  #
46
45
  # ### Common Uses
47
46
  #
48
- # You can use a Hash to give names to objects:
47
+ # You can use a `Hash` to give names to objects:
49
48
  #
50
49
  # person = {name: 'Matz', language: 'Ruby'}
51
50
  # person # => {:name=>"Matz", :language=>"Ruby"}
52
51
  #
53
- # You can use a Hash to give names to method arguments:
52
+ # You can use a `Hash` to give names to method arguments:
54
53
  #
55
54
  # def some_method(hash)
56
55
  # p hash
57
56
  # end
58
57
  # some_method({foo: 0, bar: 1, baz: 2}) # => {:foo=>0, :bar=>1, :baz=>2}
59
58
  #
60
- # Note: when the last argument in a method call is a Hash, the curly braces may
61
- # be omitted:
59
+ # Note: when the last argument in a method call is a `Hash`, the curly braces
60
+ # may be omitted:
62
61
  #
63
62
  # some_method(foo: 0, bar: 1, baz: 2) # => {:foo=>0, :bar=>1, :baz=>2}
64
63
  #
65
- # You can use a Hash to initialize an object:
64
+ # You can use a `Hash` to initialize an object:
66
65
  #
67
66
  # class Dev
68
67
  # attr_accessor :name, :language
@@ -74,58 +73,56 @@
74
73
  # matz = Dev.new(name: 'Matz', language: 'Ruby')
75
74
  # matz # => #<Dev: @name="Matz", @language="Ruby">
76
75
  #
77
- # ### Creating a Hash
76
+ # ### Creating a `Hash`
78
77
  #
79
- # You can create a Hash object explicitly with:
78
+ # You can create a `Hash` object explicitly with:
80
79
  #
81
80
  # * A [hash literal](rdoc-ref:syntax/literals.rdoc@Hash+Literals).
82
81
  #
83
- #
84
82
  # You can convert certain objects to Hashes with:
85
83
  #
86
84
  # * Method #Hash.
87
85
  #
86
+ # You can create a `Hash` by calling method Hash.new.
88
87
  #
89
- # You can create a Hash by calling method Hash.new.
90
- #
91
- # Create an empty Hash:
88
+ # Create an empty `Hash`:
92
89
  #
93
90
  # h = Hash.new
94
91
  # h # => {}
95
92
  # h.class # => Hash
96
93
  #
97
- # You can create a Hash by calling method Hash.[].
94
+ # You can create a `Hash` by calling method Hash.[].
98
95
  #
99
- # Create an empty Hash:
96
+ # Create an empty `Hash`:
100
97
  #
101
98
  # h = Hash[]
102
99
  # h # => {}
103
100
  #
104
- # Create a Hash with initial entries:
101
+ # Create a `Hash` with initial entries:
105
102
  #
106
103
  # h = Hash[foo: 0, bar: 1, baz: 2]
107
104
  # h # => {:foo=>0, :bar=>1, :baz=>2}
108
105
  #
109
- # You can create a Hash by using its literal form (curly braces).
106
+ # You can create a `Hash` by using its literal form (curly braces).
110
107
  #
111
- # Create an empty Hash:
108
+ # Create an empty `Hash`:
112
109
  #
113
110
  # h = {}
114
111
  # h # => {}
115
112
  #
116
- # Create a Hash with initial entries:
113
+ # Create a `Hash` with initial entries:
117
114
  #
118
115
  # h = {foo: 0, bar: 1, baz: 2}
119
116
  # h # => {:foo=>0, :bar=>1, :baz=>2}
120
117
  #
121
- # ### Hash Value Basics
118
+ # ### `Hash` Value Basics
122
119
  #
123
- # The simplest way to retrieve a Hash value (instance method #[]):
120
+ # The simplest way to retrieve a `Hash` value (instance method #[]):
124
121
  #
125
122
  # h = {foo: 0, bar: 1, baz: 2}
126
123
  # h[:foo] # => 0
127
124
  #
128
- # The simplest way to create or update a Hash value (instance method #[]=):
125
+ # The simplest way to create or update a `Hash` value (instance method #[]=):
129
126
  #
130
127
  # h = {foo: 0, bar: 1, baz: 2}
131
128
  # h[:bat] = 3 # => 3
@@ -133,7 +130,7 @@
133
130
  # h[:foo] = 4 # => 4
134
131
  # h # => {:foo=>4, :bar=>1, :baz=>2, :bat=>3}
135
132
  #
136
- # The simplest way to delete a Hash entry (instance method #delete):
133
+ # The simplest way to delete a `Hash` entry (instance method #delete):
137
134
  #
138
135
  # h = {foo: 0, bar: 1, baz: 2}
139
136
  # h.delete(:bar) # => 1
@@ -141,15 +138,14 @@
141
138
  #
142
139
  # ### Entry Order
143
140
  #
144
- # A Hash object presents its entries in the order of their creation. This is
141
+ # A `Hash` object presents its entries in the order of their creation. This is
145
142
  # seen in:
146
143
  #
147
144
  # * Iterative methods such as `each`, `each_key`, `each_pair`, `each_value`.
148
145
  # * Other order-sensitive methods such as `shift`, `keys`, `values`.
149
146
  # * The String returned by method `inspect`.
150
147
  #
151
- #
152
- # A new Hash has its initial ordering per the given entries:
148
+ # A new `Hash` has its initial ordering per the given entries:
153
149
  #
154
150
  # h = Hash[foo: 0, bar: 1]
155
151
  # h # => {:foo=>0, :bar=>1}
@@ -170,18 +166,18 @@
170
166
  # h[:foo] = 5
171
167
  # h # => {:bar=>1, :baz=>3, :foo=>5}
172
168
  #
173
- # ### Hash Keys
169
+ # ### `Hash` Keys
174
170
  #
175
- # #### Hash Key Equivalence
171
+ # #### `Hash` Key Equivalence
176
172
  #
177
173
  # Two objects are treated as the same hash key when their `hash` value is
178
174
  # identical and the two objects are `eql?` to each other.
179
175
  #
180
- # #### Modifying an Active Hash Key
176
+ # #### Modifying an Active `Hash` Key
181
177
  #
182
- # Modifying a Hash key while it is in use damages the hash's index.
178
+ # Modifying a `Hash` key while it is in use damages the hash's index.
183
179
  #
184
- # This Hash has keys that are Arrays:
180
+ # This `Hash` has keys that are Arrays:
185
181
  #
186
182
  # a0 = [ :foo, :bar ]
187
183
  # a1 = [ :baz, :bat ]
@@ -195,7 +191,7 @@
195
191
  # a0[0] = :bam
196
192
  # a0.hash # => 1069447059
197
193
  #
198
- # And damages the Hash index:
194
+ # And damages the `Hash` index:
199
195
  #
200
196
  # h.include?(a0) # => false
201
197
  # h[a0] # => nil
@@ -215,10 +211,10 @@
215
211
  # first_key = h.keys.first
216
212
  # first_key.frozen? # => true
217
213
  #
218
- # #### User-Defined Hash Keys
214
+ # #### User-Defined `Hash` Keys
219
215
  #
220
- # To be useable as a Hash key, objects must implement the methods `hash` and
221
- # `eql?`. Note: this requirement does not apply if the Hash uses
216
+ # To be usable as a `Hash` key, objects must implement the methods `hash` and
217
+ # `eql?`. Note: this requirement does not apply if the `Hash` uses
222
218
  # #compare_by_identity since comparison will then rely on the keys' object id
223
219
  # instead of `hash` and `eql?`.
224
220
  #
@@ -307,7 +303,7 @@
307
303
  #
308
304
  # #### Default Proc
309
305
  #
310
- # When the default proc for a Hash is set (i.e., not `nil`), the default value
306
+ # When the default proc for a `Hash` is set (i.e., not `nil`), the default value
311
307
  # returned by method #[] is determined by the default proc alone.
312
308
  #
313
309
  # You can retrieve the default proc with method #default_proc:
@@ -324,8 +320,8 @@
324
320
  # h.default_proc.class # => Proc
325
321
  #
326
322
  # When the default proc is set (i.e., not `nil`) and method #[] is called with
327
- # with a non-existent key, #[] calls the default proc with both the Hash object
328
- # itself and the missing key, then returns the proc's return value:
323
+ # with a non-existent key, #[] calls the default proc with both the `Hash`
324
+ # object itself and the missing key, then returns the proc's return value:
329
325
  #
330
326
  # h = Hash.new { |hash, key| "Default value for #{key}" }
331
327
  # h[:nosuch] # => "Default value for nosuch"
@@ -351,14 +347,13 @@
351
347
  #
352
348
  # ### What's Here
353
349
  #
354
- # First, what's elsewhere. Class Hash:
350
+ # First, what's elsewhere. Class `Hash`:
355
351
  #
356
352
  # * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
357
353
  # * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
358
354
  # provides dozens of additional methods.
359
355
  #
360
- #
361
- # Here, class Hash provides methods that are useful for:
356
+ # Here, class `Hash` provides methods that are useful for:
362
357
  #
363
358
  # * [Creating a Hash](rdoc-ref:Hash@Methods+for+Creating+a+Hash)
364
359
  # * [Setting Hash State](rdoc-ref:Hash@Methods+for+Setting+Hash+State)
@@ -373,17 +368,15 @@
373
368
  # Values](rdoc-ref:Hash@Methods+for+Transforming+Keys+and+Values)
374
369
  # * [And more....](rdoc-ref:Hash@Other+Methods)
375
370
  #
371
+ # Class `Hash` also includes methods from module Enumerable.
376
372
  #
377
- # Class Hash also includes methods from module Enumerable.
378
- #
379
- # #### Methods for Creating a Hash
373
+ # #### Methods for Creating a `Hash`
380
374
  #
381
375
  # * ::[]: Returns a new hash populated with given objects.
382
376
  # * ::new: Returns a new empty hash.
383
377
  # * ::try_convert: Returns a new hash created from a given object.
384
378
  #
385
- #
386
- # #### Methods for Setting Hash State
379
+ # #### Methods for Setting `Hash` State
387
380
  #
388
381
  # * #compare_by_identity: Sets `self` to consider only identity in comparing
389
382
  # keys.
@@ -392,7 +385,6 @@
392
385
  # * #rehash: Rebuilds the hash table by recomputing the hash index for each
393
386
  # key.
394
387
  #
395
- #
396
388
  # #### Methods for Querying
397
389
  #
398
390
  # * #any?: Returns whether any element satisfies a given criterion.
@@ -403,12 +395,11 @@
403
395
  # * #empty?: Returns whether there are no entries.
404
396
  # * #eql?: Returns whether a given object is equal to `self`.
405
397
  # * #hash: Returns the integer hash code.
406
- # * #has_value?: Returns whether a given object is a value in `self`.
407
- # * #include?, #has_key?, #member?, #key?: Returns whether a given object is a
408
- # key in `self`.
409
- # * #length, #size: Returns the count of entries.
410
- # * #value?: Returns whether a given object is a value in `self`.
411
- #
398
+ # * #has_value? (aliased as #value?): Returns whether a given object is a
399
+ # value in `self`.
400
+ # * #include? (aliased as #has_key?, #member?, #key?): Returns whether a given
401
+ # object is a key in `self`.
402
+ # * #size (aliased as #length): Returns the count of entries.
412
403
  #
413
404
  # #### Methods for Comparing
414
405
  #
@@ -418,7 +409,6 @@
418
409
  # * #>: Returns whether `self` is a proper superset of a given object
419
410
  # * #>=: Returns whether `self` is a superset of a given object.
420
411
  #
421
- #
422
412
  # #### Methods for Fetching
423
413
  #
424
414
  # * #[]: Returns the value associated with a given key.
@@ -435,16 +425,14 @@
435
425
  # * #values: Returns an array containing all values in `self`/
436
426
  # * #values_at: Returns an array containing values for given keys.
437
427
  #
438
- #
439
428
  # #### Methods for Assigning
440
429
  #
441
- # * #[]=, #store: Associates a given key with a given value.
430
+ # * #[]= (aliased as #store): Associates a given key with a given value.
442
431
  # * #merge: Returns the hash formed by merging each given hash into a copy of
443
432
  # `self`.
444
- # * #merge!, #update: Merges each given hash into `self`.
445
- # * #replace: Replaces the entire contents of `self` with the contents of a
446
- # given hash.
447
- #
433
+ # * #update (aliased as #merge!): Merges each given hash into `self`.
434
+ # * #replace (aliased as #initialize_copy): Replaces the entire contents of
435
+ # `self` with the contents of a given hash.
448
436
  #
449
437
  # #### Methods for Deleting
450
438
  #
@@ -454,40 +442,39 @@
454
442
  # * #compact!: Removes all `nil`-valued entries from `self`.
455
443
  # * #delete: Removes the entry for a given key.
456
444
  # * #delete_if: Removes entries selected by a given block.
457
- # * #filter!, #select!: Keep only those entries selected by a given block.
445
+ # * #select! (aliased as #filter!): Keep only those entries selected by a
446
+ # given block.
458
447
  # * #keep_if: Keep only those entries selected by a given block.
459
448
  # * #reject!: Removes entries selected by a given block.
460
449
  # * #shift: Removes and returns the first entry.
461
450
  #
462
- #
463
451
  # These methods return a copy of `self` with some entries removed:
464
452
  #
465
453
  # * #compact: Returns a copy of `self` with all `nil`-valued entries removed.
466
454
  # * #except: Returns a copy of `self` with entries removed for specified keys.
467
- # * #filter, #select: Returns a copy of `self` with only those entries
468
- # selected by a given block.
455
+ # * #select (aliased as #filter): Returns a copy of `self` with only those
456
+ # entries selected by a given block.
469
457
  # * #reject: Returns a copy of `self` with entries removed as specified by a
470
458
  # given block.
471
459
  # * #slice: Returns a hash containing the entries for given keys.
472
460
  #
473
- #
474
461
  # #### Methods for Iterating
475
- # * #each, #each_pair: Calls a given block with each key-value pair.
462
+ # * #each_pair (aliased as #each): Calls a given block with each key-value
463
+ # pair.
476
464
  # * #each_key: Calls a given block with each key.
477
465
  # * #each_value: Calls a given block with each value.
478
466
  #
479
- #
480
467
  # #### Methods for Converting
481
468
  #
482
- # * #inspect, #to_s: Returns a new String containing the hash entries.
469
+ # * #inspect (aliased as #to_s): Returns a new String containing the hash
470
+ # entries.
483
471
  # * #to_a: Returns a new array of 2-element arrays; each nested array contains
484
472
  # a key-value pair from `self`.
485
- # * #to_h: Returns `self` if a Hash; if a subclass of Hash, returns a Hash
486
- # containing the entries from `self`.
473
+ # * #to_h: Returns `self` if a `Hash`; if a subclass of `Hash`, returns a
474
+ # `Hash` containing the entries from `self`.
487
475
  # * #to_hash: Returns `self`.
488
476
  # * #to_proc: Returns a proc that maps a given key to its value.
489
477
  #
490
- #
491
478
  # #### Methods for Transforming Keys and Values
492
479
  #
493
480
  # * #transform_keys: Returns a copy of `self` with modified keys.
@@ -495,7 +482,6 @@
495
482
  # * #transform_values: Returns a copy of `self` with modified values.
496
483
  # * #transform_values!: Modifies values in `self`.
497
484
  #
498
- #
499
485
  # #### Other Methods
500
486
  # * #flatten: Returns an array that is a 1-dimensional flattening of `self`.
501
487
  # * #invert: Returns a hash with the each key-value pair inverted.
@@ -516,23 +502,23 @@ class Hash[unchecked out K, unchecked out V] < Object
516
502
  # - Hash[ [*2_element_arrays] ] -> new_hash
517
503
  # - Hash[*objects] -> new_hash
518
504
  # -->
519
- # Returns a new Hash object populated with the given objects, if any. See
505
+ # Returns a new `Hash` object populated with the given objects, if any. See
520
506
  # Hash::new.
521
507
  #
522
- # With no argument, returns a new empty Hash.
508
+ # With no argument, returns a new empty `Hash`.
523
509
  #
524
- # When the single given argument is a Hash, returns a new Hash populated with
525
- # the entries from the given Hash, excluding the default value or proc.
510
+ # When the single given argument is a `Hash`, returns a new `Hash` populated
511
+ # with the entries from the given `Hash`, excluding the default value or proc.
526
512
  #
527
513
  # h = {foo: 0, bar: 1, baz: 2}
528
514
  # Hash[h] # => {:foo=>0, :bar=>1, :baz=>2}
529
515
  #
530
516
  # When the single given argument is an Array of 2-element Arrays, returns a new
531
- # Hash object wherein each 2-element array forms a key-value entry:
517
+ # `Hash` object wherein each 2-element array forms a key-value entry:
532
518
  #
533
519
  # Hash[ [ [:foo, 0], [:bar, 1] ] ] # => {:foo=>0, :bar=>1}
534
520
  #
535
- # When the argument count is an even number; returns a new Hash object wherein
521
+ # When the argument count is an even number; returns a new `Hash` object wherein
536
522
  # each successive pair of arguments has become a key-value entry:
537
523
  #
538
524
  # Hash[:foo, 0, :bar, 1] # => {:foo=>0, :bar=>1}
@@ -547,14 +533,14 @@ class Hash[unchecked out K, unchecked out V] < Object
547
533
  # rdoc-file=hash.c
548
534
  # - Hash.try_convert(obj) -> obj, new_hash, or nil
549
535
  # -->
550
- # If `obj` is a Hash object, returns `obj`.
536
+ # If `obj` is a `Hash` object, returns `obj`.
551
537
  #
552
538
  # Otherwise if `obj` responds to `:to_hash`, calls `obj.to_hash` and returns the
553
539
  # result.
554
540
  #
555
541
  # Returns `nil` if `obj` does not respond to `:to_hash`
556
542
  #
557
- # Raises an exception unless `obj.to_hash` returns a Hash object.
543
+ # Raises an exception unless `obj.to_hash` returns a `Hash` object.
558
544
  #
559
545
  def self.try_convert: [U, V] (_ToHash[U, V]) -> ::Hash[U, V]
560
546
  | (untyped) -> (::Hash[untyped, untyped] | nil)
@@ -591,11 +577,10 @@ class Hash[unchecked out K, unchecked out V] < Object
591
577
  # - hash == object -> true or false
592
578
  # -->
593
579
  # Returns `true` if all of the following are true:
594
- # * `object` is a Hash object.
580
+ # * `object` is a `Hash` object.
595
581
  # * `hash` and `object` have the same keys (regardless of order).
596
582
  # * For each key `key`, `hash[key] == object[key]`.
597
583
  #
598
- #
599
584
  # Otherwise, returns `false`.
600
585
  #
601
586
  # Equal:
@@ -843,7 +828,7 @@ class Hash[unchecked out K, unchecked out V] < Object
843
828
  # rdoc-file=hash.c
844
829
  # - hash.default_proc = proc -> proc
845
830
  # -->
846
- # Sets the default proc for `self` to `proc`: (see [Default
831
+ # Sets the default proc for `self` to `proc` (see [Default
847
832
  # Values](rdoc-ref:Hash@Default+Values)):
848
833
  # h = {}
849
834
  # h.default_proc # => nil
@@ -1052,17 +1037,15 @@ class Hash[unchecked out K, unchecked out V] < Object
1052
1037
 
1053
1038
  # <!--
1054
1039
  # rdoc-file=hash.c
1055
- # - hash.eql? object -> true or false
1040
+ # - hash.eql?(object) -> true or false
1056
1041
  # -->
1057
1042
  # Returns `true` if all of the following are true:
1058
- # * `object` is a Hash object.
1043
+ # * `object` is a `Hash` object.
1059
1044
  # * `hash` and `object` have the same keys (regardless of order).
1060
- # * For each key `key`, `h[key] eql? object[key]`.
1061
- #
1045
+ # * For each key `key`, `h[key].eql?(object[key])`.
1062
1046
  #
1063
1047
  # Otherwise, returns `false`.
1064
1048
  #
1065
- # Equal:
1066
1049
  # h1 = {foo: 0, bar: 1, baz: 2}
1067
1050
  # h2 = {foo: 0, bar: 1, baz: 2}
1068
1051
  # h1.eql? h2 # => true
@@ -1075,7 +1058,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1075
1058
  # rdoc-file=hash.c
1076
1059
  # - hsh.except(*keys) -> a_hash
1077
1060
  # -->
1078
- # Returns a new Hash excluding entries for the given `keys`:
1061
+ # Returns a new `Hash` excluding entries for the given `keys`:
1079
1062
  # h = { a: 100, b: 200, c: 300 }
1080
1063
  # h.except(:a) #=> {:b=>200, :c=>300}
1081
1064
  #
@@ -1133,8 +1116,8 @@ class Hash[unchecked out K, unchecked out V] < Object
1133
1116
  | [X] (*K) { (K) -> X } -> ::Array[V | X]
1134
1117
 
1135
1118
  # <!-- rdoc-file=hash.c -->
1136
- # Returns a new Hash object whose entries are those for which the block returns
1137
- # a truthy value:
1119
+ # Returns a new `Hash` object whose entries are those for which the block
1120
+ # returns a truthy value:
1138
1121
  # h = {foo: 0, bar: 1, baz: 2}
1139
1122
  # h.select {|key, value| value < 2 } # => {:foo=>0, :bar=>1}
1140
1123
  #
@@ -1216,7 +1199,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1216
1199
  # -->
1217
1200
  # Returns the Integer hash-code for the hash.
1218
1201
  #
1219
- # Two Hash objects have the same hash-code if their content is the same
1202
+ # Two `Hash` objects have the same hash-code if their content is the same
1220
1203
  # (regardless of order):
1221
1204
  # h1 = {foo: 0, bar: 1, baz: 2}
1222
1205
  # h2 = {baz: 2, bar: 1, foo: 0}
@@ -1243,7 +1226,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1243
1226
  # Returns a new String containing the hash entries:
1244
1227
  #
1245
1228
  # h = {foo: 0, bar: 1, baz: 2}
1246
- # h.inspect # => "{:foo=>0, :bar=>1, :baz=>2}"
1229
+ # h.inspect # => "{foo: 0, bar: 1, baz: 2}"
1247
1230
  #
1248
1231
  def inspect: () -> String
1249
1232
 
@@ -1251,7 +1234,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1251
1234
  # rdoc-file=hash.c
1252
1235
  # - hash.invert -> new_hash
1253
1236
  # -->
1254
- # Returns a new Hash object with the each key-value pair inverted:
1237
+ # Returns a new `Hash` object with the each key-value pair inverted:
1255
1238
  # h = {foo: 0, bar: 1, baz: 2}
1256
1239
  # h1 = h.invert
1257
1240
  # h1 # => {0=>:foo, 1=>:bar, 2=>:baz}
@@ -1328,20 +1311,19 @@ class Hash[unchecked out K, unchecked out V] < Object
1328
1311
  # - hash.merge(*other_hashes) -> new_hash
1329
1312
  # - hash.merge(*other_hashes) { |key, old_value, new_value| ... } -> new_hash
1330
1313
  # -->
1331
- # Returns the new Hash formed by merging each of `other_hashes` into a copy of
1314
+ # Returns the new `Hash` formed by merging each of `other_hashes` into a copy of
1332
1315
  # `self`.
1333
1316
  #
1334
- # Each argument in `other_hashes` must be a Hash.
1317
+ # Each argument in `other_hashes` must be a `Hash`.
1335
1318
  #
1336
1319
  # ---
1337
1320
  #
1338
1321
  # With arguments and no block:
1339
- # * Returns the new Hash object formed by merging each successive Hash in
1322
+ # * Returns the new `Hash` object formed by merging each successive `Hash` in
1340
1323
  # `other_hashes` into `self`.
1341
1324
  # * Each new-key entry is added at the end.
1342
1325
  # * Each duplicate-key entry's value overwrites the previous value.
1343
1326
  #
1344
- #
1345
1327
  # Example:
1346
1328
  # h = {foo: 0, bar: 1, baz: 2}
1347
1329
  # h1 = {bat: 3, bar: 4}
@@ -1349,15 +1331,14 @@ class Hash[unchecked out K, unchecked out V] < Object
1349
1331
  # h.merge(h1, h2) # => {:foo=>0, :bar=>4, :baz=>2, :bat=>6, :bam=>5}
1350
1332
  #
1351
1333
  # With arguments and a block:
1352
- # * Returns a new Hash object that is the merge of `self` and each given hash.
1334
+ # * Returns a new `Hash` object that is the merge of `self` and each given
1335
+ # hash.
1353
1336
  # * The given hashes are merged left to right.
1354
1337
  # * Each new-key entry is added at the end.
1355
1338
  # * For each duplicate key:
1356
1339
  # * Calls the block with the key and the old and new values.
1357
1340
  # * The block's return value becomes the new value for the entry.
1358
1341
  #
1359
- #
1360
- #
1361
1342
  # Example:
1362
1343
  # h = {foo: 0, bar: 1, baz: 2}
1363
1344
  # h1 = {bat: 3, bar: 4}
@@ -1369,7 +1350,6 @@ class Hash[unchecked out K, unchecked out V] < Object
1369
1350
  # * Returns a copy of `self`.
1370
1351
  # * The block, if given, is ignored.
1371
1352
  #
1372
- #
1373
1353
  # Example:
1374
1354
  # h = {foo: 0, bar: 1, baz: 2}
1375
1355
  # h.merge # => {:foo=>0, :bar=>1, :baz=>2}
@@ -1382,7 +1362,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1382
1362
  # <!-- rdoc-file=hash.c -->
1383
1363
  # Merges each of `other_hashes` into `self`; returns `self`.
1384
1364
  #
1385
- # Each argument in `other_hashes` must be a Hash.
1365
+ # Each argument in `other_hashes` must be a `Hash`.
1386
1366
  #
1387
1367
  # With arguments and no block:
1388
1368
  # * Returns `self`, after the given hashes are merged into it.
@@ -1390,7 +1370,6 @@ class Hash[unchecked out K, unchecked out V] < Object
1390
1370
  # * Each new entry is added at the end.
1391
1371
  # * Each duplicate-key entry's value overwrites the previous value.
1392
1372
  #
1393
- #
1394
1373
  # Example:
1395
1374
  # h = {foo: 0, bar: 1, baz: 2}
1396
1375
  # h1 = {bat: 3, bar: 4}
@@ -1405,8 +1384,6 @@ class Hash[unchecked out K, unchecked out V] < Object
1405
1384
  # * Calls the block with the key and the old and new values.
1406
1385
  # * The block's return value becomes the new value for the entry.
1407
1386
  #
1408
- #
1409
- #
1410
1387
  # Example:
1411
1388
  # h = {foo: 0, bar: 1, baz: 2}
1412
1389
  # h1 = {bat: 3, bar: 4}
@@ -1418,7 +1395,6 @@ class Hash[unchecked out K, unchecked out V] < Object
1418
1395
  # * Returns `self`, unmodified.
1419
1396
  # * The block, if given, is ignored.
1420
1397
  #
1421
- #
1422
1398
  # Example:
1423
1399
  # h = {foo: 0, bar: 1, baz: 2}
1424
1400
  # h.merge # => {:foo=>0, :bar=>1, :baz=>2}
@@ -1460,7 +1436,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1460
1436
  # - hash.reject {|key, value| ... } -> new_hash
1461
1437
  # - hash.reject -> new_enumerator
1462
1438
  # -->
1463
- # Returns a new Hash object whose entries are all those from `self` for which
1439
+ # Returns a new `Hash` object whose entries are all those from `self` for which
1464
1440
  # the block returns `false` or `nil`:
1465
1441
  # h = {foo: 0, bar: 1, baz: 2}
1466
1442
  # h1 = h.reject {|key, value| key.start_with?('b') }
@@ -1508,8 +1484,8 @@ class Hash[unchecked out K, unchecked out V] < Object
1508
1484
  # - hash.select {|key, value| ... } -> new_hash
1509
1485
  # - hash.select -> new_enumerator
1510
1486
  # -->
1511
- # Returns a new Hash object whose entries are those for which the block returns
1512
- # a truthy value:
1487
+ # Returns a new `Hash` object whose entries are those for which the block
1488
+ # returns a truthy value:
1513
1489
  # h = {foo: 0, bar: 1, baz: 2}
1514
1490
  # h.select {|key, value| value < 2 } # => {:foo=>0, :bar=>1}
1515
1491
  #
@@ -1568,7 +1544,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1568
1544
  # rdoc-file=hash.c
1569
1545
  # - hash.slice(*keys) -> new_hash
1570
1546
  # -->
1571
- # Returns a new Hash object containing the entries for the given `keys`:
1547
+ # Returns a new `Hash` object containing the entries for the given `keys`:
1572
1548
  # h = {foo: 0, bar: 1, baz: 2}
1573
1549
  # h.slice(:baz, :foo) # => {:baz=>2, :foo=>0}
1574
1550
  #
@@ -1611,12 +1587,13 @@ class Hash[unchecked out K, unchecked out V] < Object
1611
1587
  # - hash.to_h -> self or new_hash
1612
1588
  # - hash.to_h {|key, value| ... } -> new_hash
1613
1589
  # -->
1614
- # For an instance of Hash, returns `self`.
1590
+ # For an instance of `Hash`, returns `self`.
1615
1591
  #
1616
- # For a subclass of Hash, returns a new Hash containing the content of `self`.
1592
+ # For a subclass of `Hash`, returns a new `Hash` containing the content of
1593
+ # `self`.
1617
1594
  #
1618
- # When a block is given, returns a new Hash object whose content is based on the
1619
- # block; the block should return a 2-element Array object specifying the
1595
+ # When a block is given, returns a new `Hash` object whose content is based on
1596
+ # the block; the block should return a 2-element Array object specifying the
1620
1597
  # key-value pair to be included in the returned Array:
1621
1598
  # h = {foo: 0, bar: 1, baz: 2}
1622
1599
  # h1 = h.to_h {|key, value| [value, key] }
@@ -1651,7 +1628,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1651
1628
  # Returns a new String containing the hash entries:
1652
1629
  #
1653
1630
  # h = {foo: 0, bar: 1, baz: 2}
1654
- # h.inspect # => "{:foo=>0, :bar=>1, :baz=>2}"
1631
+ # h.inspect # => "{foo: 0, bar: 1, baz: 2}"
1655
1632
  #
1656
1633
  alias to_s inspect
1657
1634
 
@@ -1662,11 +1639,10 @@ class Hash[unchecked out K, unchecked out V] < Object
1662
1639
  # - hash.transform_keys(hash2) {|other_key| ...} -> new_hash
1663
1640
  # - hash.transform_keys -> new_enumerator
1664
1641
  # -->
1665
- # Returns a new Hash object; each entry has:
1642
+ # Returns a new `Hash` object; each entry has:
1666
1643
  # * A key provided by the block.
1667
1644
  # * The value from `self`.
1668
1645
  #
1669
- #
1670
1646
  # An optional hash argument can be provided to map keys to new keys. Any key not
1671
1647
  # given will be mapped using the provided block, or remain the same if no block
1672
1648
  # is given.
@@ -1714,11 +1690,10 @@ class Hash[unchecked out K, unchecked out V] < Object
1714
1690
  # - hash.transform_values {|value| ... } -> new_hash
1715
1691
  # - hash.transform_values -> new_enumerator
1716
1692
  # -->
1717
- # Returns a new Hash object; each entry has:
1693
+ # Returns a new `Hash` object; each entry has:
1718
1694
  # * A key from `self`.
1719
1695
  # * A value provided by the block.
1720
1696
  #
1721
- #
1722
1697
  # Transform values:
1723
1698
  # h = {foo: 0, bar: 1, baz: 2}
1724
1699
  # h1 = h.transform_values {|value| value * 100}
@@ -1760,7 +1735,7 @@ class Hash[unchecked out K, unchecked out V] < Object
1760
1735
  # -->
1761
1736
  # Merges each of `other_hashes` into `self`; returns `self`.
1762
1737
  #
1763
- # Each argument in `other_hashes` must be a Hash.
1738
+ # Each argument in `other_hashes` must be a `Hash`.
1764
1739
  #
1765
1740
  # With arguments and no block:
1766
1741
  # * Returns `self`, after the given hashes are merged into it.
@@ -1768,7 +1743,6 @@ class Hash[unchecked out K, unchecked out V] < Object
1768
1743
  # * Each new entry is added at the end.
1769
1744
  # * Each duplicate-key entry's value overwrites the previous value.
1770
1745
  #
1771
- #
1772
1746
  # Example:
1773
1747
  # h = {foo: 0, bar: 1, baz: 2}
1774
1748
  # h1 = {bat: 3, bar: 4}
@@ -1783,8 +1757,6 @@ class Hash[unchecked out K, unchecked out V] < Object
1783
1757
  # * Calls the block with the key and the old and new values.
1784
1758
  # * The block's return value becomes the new value for the entry.
1785
1759
  #
1786
- #
1787
- #
1788
1760
  # Example:
1789
1761
  # h = {foo: 0, bar: 1, baz: 2}
1790
1762
  # h1 = {bat: 3, bar: 4}
@@ -1796,7 +1768,6 @@ class Hash[unchecked out K, unchecked out V] < Object
1796
1768
  # * Returns `self`, unmodified.
1797
1769
  # * The block, if given, is ignored.
1798
1770
  #
1799
- #
1800
1771
  # Example:
1801
1772
  # h = {foo: 0, bar: 1, baz: 2}
1802
1773
  # h.merge # => {:foo=>0, :bar=>1, :baz=>2}
@@ -1837,37 +1808,45 @@ class Hash[unchecked out K, unchecked out V] < Object
1837
1808
  private
1838
1809
 
1839
1810
  # <!--
1840
- # rdoc-file=hash.c
1811
+ # rdoc-file=hash.rb
1841
1812
  # - Hash.new(default_value = nil) -> new_hash
1813
+ # - Hash.new(default_value = nil, capacity: size) -> new_hash
1842
1814
  # - Hash.new {|hash, key| ... } -> new_hash
1815
+ # - Hash.new(capacity: size) {|hash, key| ... } -> new_hash
1843
1816
  # -->
1844
- # Returns a new empty Hash object.
1817
+ # Returns a new empty `Hash` object.
1845
1818
  #
1846
1819
  # The initial default value and initial default proc for the new hash depend on
1847
1820
  # which form above was used. See [Default Values](rdoc-ref:Hash@Default+Values).
1848
1821
  #
1849
- # If neither an argument nor a block given, initializes both the default value
1850
- # and the default proc to `nil`:
1822
+ # If neither an argument nor a block is given, initializes both the default
1823
+ # value and the default proc to `nil`:
1851
1824
  # h = Hash.new
1852
1825
  # h.default # => nil
1853
1826
  # h.default_proc # => nil
1854
1827
  #
1855
- # If argument `default_value` given but no block given, initializes the default
1856
- # value to the given `default_value` and the default proc to `nil`:
1828
+ # If argument `default_value` is given but no block is given, initializes the
1829
+ # default value to the given `default_value` and the default proc to `nil`:
1857
1830
  # h = Hash.new(false)
1858
1831
  # h.default # => false
1859
1832
  # h.default_proc # => nil
1860
1833
  #
1861
- # If a block given but no argument, stores the block as the default proc and
1862
- # sets the default value to `nil`:
1834
+ # If a block is given but no `default_value`, stores the block as the default
1835
+ # proc and sets the default value to `nil`:
1863
1836
  # h = Hash.new {|hash, key| "Default value for #{key}" }
1864
1837
  # h.default # => nil
1865
1838
  # h.default_proc.class # => Proc
1866
1839
  # h[:nosuch] # => "Default value for nosuch"
1867
1840
  #
1868
- def initialize: () -> void
1869
- | (untyped default) -> void
1870
- | [A, B] () { (Hash[A, B] hash, A key) -> B } -> void
1841
+ # If both a block and a `default_value` are given, raises an `ArgumentError`
1842
+ #
1843
+ # If the optional keyword argument `capacity` is given, the hash will be
1844
+ # allocated with enough capacity to accommodate this many keys without having to
1845
+ # be resized.
1846
+ #
1847
+ def initialize: (?capacity: int) -> void
1848
+ | (V default, ?capacity: int) -> void
1849
+ | (?capacity: int) { (Hash[K, V] hash, K key) -> V } -> void
1871
1850
 
1872
1851
  # <!--
1873
1852
  # rdoc-file=hash.c