rbs 4.0.0.dev.4 → 4.0.0

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 (281) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -14
  3. data/.github/workflows/bundle-update.yml +60 -0
  4. data/.github/workflows/c-check.yml +18 -11
  5. data/.github/workflows/comments.yml +5 -3
  6. data/.github/workflows/dependabot.yml +2 -2
  7. data/.github/workflows/ruby.yml +27 -34
  8. data/.github/workflows/rust.yml +95 -0
  9. data/.github/workflows/typecheck.yml +2 -2
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +1 -1
  12. data/CHANGELOG.md +323 -0
  13. data/README.md +1 -1
  14. data/Rakefile +43 -33
  15. data/Steepfile +1 -0
  16. data/config.yml +426 -24
  17. data/core/array.rbs +307 -227
  18. data/core/basic_object.rbs +9 -8
  19. data/core/binding.rbs +0 -2
  20. data/core/builtin.rbs +2 -2
  21. data/core/class.rbs +6 -5
  22. data/core/comparable.rbs +55 -34
  23. data/core/complex.rbs +104 -78
  24. data/core/dir.rbs +61 -49
  25. data/core/encoding.rbs +12 -15
  26. data/core/enumerable.rbs +179 -87
  27. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  28. data/core/enumerator.rbs +65 -2
  29. data/core/errno.rbs +11 -2
  30. data/core/errors.rbs +58 -29
  31. data/core/exception.rbs +13 -13
  32. data/core/fiber.rbs +74 -54
  33. data/core/file.rbs +280 -177
  34. data/core/file_test.rbs +3 -3
  35. data/core/float.rbs +257 -92
  36. data/core/gc.rbs +425 -281
  37. data/core/hash.rbs +1045 -739
  38. data/core/integer.rbs +135 -137
  39. data/core/io/buffer.rbs +53 -42
  40. data/core/io/wait.rbs +13 -35
  41. data/core/io.rbs +192 -144
  42. data/core/kernel.rbs +216 -155
  43. data/core/marshal.rbs +4 -4
  44. data/core/match_data.rbs +15 -13
  45. data/core/math.rbs +107 -66
  46. data/core/method.rbs +69 -33
  47. data/core/module.rbs +244 -106
  48. data/core/nil_class.rbs +7 -6
  49. data/core/numeric.rbs +74 -63
  50. data/core/object.rbs +9 -11
  51. data/core/object_space.rbs +30 -23
  52. data/core/pathname.rbs +1322 -0
  53. data/core/proc.rbs +95 -58
  54. data/core/process.rbs +222 -202
  55. data/core/ractor.rbs +371 -515
  56. data/core/random.rbs +21 -3
  57. data/core/range.rbs +159 -57
  58. data/core/rational.rbs +60 -89
  59. data/core/rbs/unnamed/argf.rbs +60 -53
  60. data/core/rbs/unnamed/env_class.rbs +19 -14
  61. data/core/rbs/unnamed/main_class.rbs +123 -0
  62. data/core/rbs/unnamed/random.rbs +11 -118
  63. data/core/regexp.rbs +258 -214
  64. data/core/ruby.rbs +53 -0
  65. data/core/ruby_vm.rbs +38 -34
  66. data/core/rubygems/config_file.rbs +5 -5
  67. data/core/rubygems/errors.rbs +4 -71
  68. data/core/rubygems/requirement.rbs +5 -5
  69. data/core/rubygems/rubygems.rbs +16 -82
  70. data/core/rubygems/version.rbs +2 -3
  71. data/core/set.rbs +490 -360
  72. data/core/signal.rbs +26 -16
  73. data/core/string.rbs +3234 -1285
  74. data/core/struct.rbs +27 -26
  75. data/core/symbol.rbs +41 -34
  76. data/core/thread.rbs +135 -67
  77. data/core/time.rbs +81 -50
  78. data/core/trace_point.rbs +41 -35
  79. data/core/true_class.rbs +2 -2
  80. data/core/unbound_method.rbs +24 -16
  81. data/core/warning.rbs +7 -7
  82. data/docs/aliases.md +79 -0
  83. data/docs/collection.md +3 -3
  84. data/docs/config.md +171 -0
  85. data/docs/encoding.md +56 -0
  86. data/docs/gem.md +0 -1
  87. data/docs/inline.md +576 -0
  88. data/docs/sigs.md +3 -3
  89. data/docs/syntax.md +46 -16
  90. data/docs/type_fingerprint.md +21 -0
  91. data/exe/rbs +1 -1
  92. data/ext/rbs_extension/ast_translation.c +544 -116
  93. data/ext/rbs_extension/ast_translation.h +3 -0
  94. data/ext/rbs_extension/class_constants.c +16 -2
  95. data/ext/rbs_extension/class_constants.h +8 -0
  96. data/ext/rbs_extension/extconf.rb +5 -1
  97. data/ext/rbs_extension/legacy_location.c +33 -56
  98. data/ext/rbs_extension/legacy_location.h +37 -0
  99. data/ext/rbs_extension/main.c +44 -35
  100. data/include/rbs/ast.h +448 -173
  101. data/include/rbs/defines.h +27 -0
  102. data/include/rbs/lexer.h +30 -11
  103. data/include/rbs/location.h +25 -44
  104. data/include/rbs/parser.h +6 -6
  105. data/include/rbs/string.h +0 -2
  106. data/include/rbs/util/rbs_allocator.h +34 -13
  107. data/include/rbs/util/rbs_assert.h +12 -1
  108. data/include/rbs/util/rbs_constant_pool.h +0 -3
  109. data/include/rbs/util/rbs_encoding.h +2 -0
  110. data/include/rbs/util/rbs_unescape.h +2 -1
  111. data/include/rbs.h +8 -0
  112. data/lib/rbs/ast/annotation.rb +1 -1
  113. data/lib/rbs/ast/comment.rb +1 -1
  114. data/lib/rbs/ast/declarations.rb +10 -10
  115. data/lib/rbs/ast/members.rb +14 -14
  116. data/lib/rbs/ast/ruby/annotations.rb +293 -3
  117. data/lib/rbs/ast/ruby/comment_block.rb +24 -0
  118. data/lib/rbs/ast/ruby/declarations.rb +198 -3
  119. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
  120. data/lib/rbs/ast/ruby/members.rb +532 -22
  121. data/lib/rbs/ast/type_param.rb +24 -4
  122. data/lib/rbs/buffer.rb +20 -15
  123. data/lib/rbs/cli/diff.rb +16 -15
  124. data/lib/rbs/cli/validate.rb +38 -106
  125. data/lib/rbs/cli.rb +52 -19
  126. data/lib/rbs/collection/config/lockfile_generator.rb +14 -2
  127. data/lib/rbs/collection/sources/git.rb +1 -0
  128. data/lib/rbs/definition.rb +1 -1
  129. data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
  130. data/lib/rbs/definition_builder/method_builder.rb +20 -0
  131. data/lib/rbs/definition_builder.rb +147 -25
  132. data/lib/rbs/diff.rb +7 -1
  133. data/lib/rbs/environment.rb +227 -74
  134. data/lib/rbs/environment_loader.rb +0 -6
  135. data/lib/rbs/errors.rb +27 -18
  136. data/lib/rbs/inline_parser.rb +342 -6
  137. data/lib/rbs/location_aux.rb +1 -1
  138. data/lib/rbs/locator.rb +5 -1
  139. data/lib/rbs/method_type.rb +5 -3
  140. data/lib/rbs/parser_aux.rb +20 -7
  141. data/lib/rbs/prototype/helpers.rb +57 -0
  142. data/lib/rbs/prototype/rb.rb +3 -28
  143. data/lib/rbs/prototype/rbi.rb +3 -20
  144. data/lib/rbs/prototype/runtime.rb +8 -0
  145. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  146. data/lib/rbs/resolver/type_name_resolver.rb +116 -38
  147. data/lib/rbs/subtractor.rb +3 -1
  148. data/lib/rbs/test/type_check.rb +19 -2
  149. data/lib/rbs/type_name.rb +1 -1
  150. data/lib/rbs/types.rb +88 -78
  151. data/lib/rbs/unit_test/type_assertions.rb +35 -8
  152. data/lib/rbs/validator.rb +2 -2
  153. data/lib/rbs/version.rb +1 -1
  154. data/lib/rbs.rb +1 -2
  155. data/lib/rdoc/discover.rb +1 -1
  156. data/lib/rdoc_plugin/parser.rb +1 -1
  157. data/rbs.gemspec +4 -3
  158. data/rust/.gitignore +1 -0
  159. data/rust/Cargo.lock +378 -0
  160. data/rust/Cargo.toml +7 -0
  161. data/rust/ruby-rbs/Cargo.toml +22 -0
  162. data/rust/ruby-rbs/build.rs +764 -0
  163. data/rust/ruby-rbs/examples/locations.rs +60 -0
  164. data/rust/ruby-rbs/src/lib.rs +1 -0
  165. data/rust/ruby-rbs/src/node/mod.rs +742 -0
  166. data/rust/ruby-rbs/tests/sanity.rs +47 -0
  167. data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
  168. data/rust/ruby-rbs-sys/Cargo.toml +23 -0
  169. data/rust/ruby-rbs-sys/build.rs +204 -0
  170. data/rust/ruby-rbs-sys/src/lib.rs +50 -0
  171. data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
  172. data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
  173. data/rust/ruby-rbs-sys/wrapper.h +1 -0
  174. data/schema/typeParam.json +17 -1
  175. data/sig/ast/ruby/annotations.rbs +315 -4
  176. data/sig/ast/ruby/comment_block.rbs +8 -0
  177. data/sig/ast/ruby/declarations.rbs +102 -4
  178. data/sig/ast/ruby/members.rbs +108 -2
  179. data/sig/cli/diff.rbs +5 -11
  180. data/sig/cli/validate.rbs +12 -8
  181. data/sig/cli.rbs +18 -18
  182. data/sig/definition.rbs +6 -1
  183. data/sig/definition_builder.rbs +2 -0
  184. data/sig/environment.rbs +70 -12
  185. data/sig/errors.rbs +13 -14
  186. data/sig/inline_parser.rbs +39 -2
  187. data/sig/locator.rbs +0 -2
  188. data/sig/manifest.yaml +0 -1
  189. data/sig/method_builder.rbs +3 -1
  190. data/sig/parser.rbs +31 -13
  191. data/sig/prototype/helpers.rbs +2 -0
  192. data/sig/resolver/type_name_resolver.rbs +35 -7
  193. data/sig/source.rbs +3 -3
  194. data/sig/type_param.rbs +13 -8
  195. data/sig/types.rbs +6 -7
  196. data/sig/unit_test/spy.rbs +0 -8
  197. data/sig/unit_test/type_assertions.rbs +11 -0
  198. data/src/ast.c +410 -153
  199. data/src/lexer.c +1392 -1313
  200. data/src/lexer.re +3 -0
  201. data/src/lexstate.c +58 -37
  202. data/src/location.c +8 -48
  203. data/src/parser.c +977 -516
  204. data/src/string.c +0 -48
  205. data/src/util/rbs_allocator.c +89 -71
  206. data/src/util/rbs_assert.c +1 -1
  207. data/src/util/rbs_buffer.c +2 -2
  208. data/src/util/rbs_constant_pool.c +10 -14
  209. data/src/util/rbs_encoding.c +4 -8
  210. data/src/util/rbs_unescape.c +56 -20
  211. data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
  212. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  213. data/stdlib/cgi/0/core.rbs +9 -393
  214. data/stdlib/cgi/0/manifest.yaml +1 -0
  215. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  216. data/stdlib/coverage/0/coverage.rbs +7 -4
  217. data/stdlib/date/0/date.rbs +92 -79
  218. data/stdlib/date/0/date_time.rbs +25 -24
  219. data/stdlib/delegate/0/delegator.rbs +10 -7
  220. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  221. data/stdlib/digest/0/digest.rbs +110 -0
  222. data/stdlib/erb/0/erb.rbs +748 -347
  223. data/stdlib/etc/0/etc.rbs +55 -50
  224. data/stdlib/fileutils/0/fileutils.rbs +158 -139
  225. data/stdlib/forwardable/0/forwardable.rbs +13 -10
  226. data/stdlib/io-console/0/io-console.rbs +2 -2
  227. data/stdlib/json/0/json.rbs +217 -136
  228. data/stdlib/monitor/0/monitor.rbs +3 -3
  229. data/stdlib/net-http/0/net-http.rbs +162 -134
  230. data/stdlib/objspace/0/objspace.rbs +17 -34
  231. data/stdlib/open-uri/0/open-uri.rbs +48 -8
  232. data/stdlib/open3/0/open3.rbs +469 -10
  233. data/stdlib/openssl/0/openssl.rbs +475 -357
  234. data/stdlib/optparse/0/optparse.rbs +26 -17
  235. data/stdlib/pathname/0/pathname.rbs +11 -1381
  236. data/stdlib/pp/0/pp.rbs +9 -8
  237. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  238. data/stdlib/pstore/0/pstore.rbs +35 -30
  239. data/stdlib/psych/0/psych.rbs +65 -12
  240. data/stdlib/psych/0/store.rbs +2 -4
  241. data/stdlib/pty/0/pty.rbs +9 -6
  242. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  243. data/stdlib/rdoc/0/code_object.rbs +2 -1
  244. data/stdlib/rdoc/0/parser.rbs +1 -1
  245. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  246. data/stdlib/rdoc/0/store.rbs +1 -1
  247. data/stdlib/resolv/0/resolv.rbs +25 -68
  248. data/stdlib/ripper/0/ripper.rbs +22 -19
  249. data/stdlib/securerandom/0/manifest.yaml +2 -0
  250. data/stdlib/securerandom/0/securerandom.rbs +7 -20
  251. data/stdlib/shellwords/0/shellwords.rbs +2 -2
  252. data/stdlib/singleton/0/singleton.rbs +3 -0
  253. data/stdlib/socket/0/addrinfo.rbs +7 -7
  254. data/stdlib/socket/0/basic_socket.rbs +3 -3
  255. data/stdlib/socket/0/ip_socket.rbs +10 -8
  256. data/stdlib/socket/0/socket.rbs +23 -10
  257. data/stdlib/socket/0/tcp_server.rbs +1 -1
  258. data/stdlib/socket/0/tcp_socket.rbs +11 -3
  259. data/stdlib/socket/0/udp_socket.rbs +1 -1
  260. data/stdlib/socket/0/unix_server.rbs +1 -1
  261. data/stdlib/stringio/0/stringio.rbs +1177 -85
  262. data/stdlib/strscan/0/string_scanner.rbs +27 -25
  263. data/stdlib/tempfile/0/tempfile.rbs +25 -21
  264. data/stdlib/time/0/time.rbs +8 -6
  265. data/stdlib/timeout/0/timeout.rbs +63 -7
  266. data/stdlib/tsort/0/cyclic.rbs +3 -0
  267. data/stdlib/tsort/0/tsort.rbs +7 -6
  268. data/stdlib/uri/0/common.rbs +42 -20
  269. data/stdlib/uri/0/file.rbs +3 -3
  270. data/stdlib/uri/0/generic.rbs +26 -18
  271. data/stdlib/uri/0/http.rbs +2 -2
  272. data/stdlib/uri/0/ldap.rbs +2 -2
  273. data/stdlib/uri/0/mailto.rbs +3 -3
  274. data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
  275. data/stdlib/zlib/0/deflate.rbs +4 -3
  276. data/stdlib/zlib/0/gzip_reader.rbs +6 -6
  277. data/stdlib/zlib/0/gzip_writer.rbs +14 -12
  278. data/stdlib/zlib/0/inflate.rbs +1 -1
  279. data/stdlib/zlib/0/need_dict.rbs +1 -1
  280. data/stdlib/zlib/0/zstream.rbs +1 -0
  281. metadata +50 -6
data/core/set.rbs CHANGED
@@ -1,425 +1,508 @@
1
- # <!-- rdoc-file=lib/set.rb -->
2
- # This library provides the Set class, which implements a collection
3
- # of unordered values with no duplicates. It is a hybrid of Array's
4
- # intuitive inter-operation facilities and Hash's fast lookup.
5
- # The method `to_set` is added to Enumerable for convenience.
6
- # Set is easy to use with Enumerable objects (implementing `each`).
7
- # Most of the initializer methods and binary operators accept generic
8
- # Enumerable objects besides sets and arrays. An Enumerable object
9
- # can be converted to Set using the `to_set` method.
10
- # Set uses Hash as storage, so you must note the following points:
1
+ # <!-- rdoc-file=set.c -->
2
+ # The Set class implements a collection of unordered values with no duplicates.
3
+ # It is a hybrid of Array's intuitive inter-operation facilities and Hash's fast
4
+ # lookup.
5
+ #
6
+ # Set is easy to use with Enumerable objects (implementing #each). Most of the
7
+ # initializer methods and binary operators accept generic Enumerable objects
8
+ # besides sets and arrays. An Enumerable object can be converted to Set using
9
+ # the `to_set` method.
10
+ #
11
+ # Set uses a data structure similar to Hash for storage, except that it only has
12
+ # keys and no values.
13
+ #
11
14
  # * Equality of elements is determined according to Object#eql? and
12
- # Object#hash. Use Set#compare_by_identity to make a set compare
13
- # its elements by their identity.
14
- # * Set assumes that the identity of each element does not change
15
- # while it is stored. Modifying an element of a set will render the
16
- # set to an unreliable state.
17
- # * When a string is to be stored, a frozen copy of the string is
18
- # stored instead unless the original string is already frozen.
15
+ # Object#hash. Use Set#compare_by_identity to make a set compare its
16
+ # elements by their identity.
17
+ # * Set assumes that the identity of each element does not change while it is
18
+ # stored. Modifying an element of a set will render the set to an
19
+ # unreliable state.
20
+ # * When a string is to be stored, a frozen copy of the string is stored
21
+ # instead unless the original string is already frozen.
22
+ #
19
23
  # ## Comparison
20
- # The comparison operators `<`, `>`, `<=`, and `>=` are implemented as
21
- # shorthand for the {proper_,}{subset?,superset?} methods. The `<=>`
22
- # operator reflects this order, or return `nil` for sets that both
23
- # have distinct elements (`{x, y}` vs. `{x, z}` for example).
24
+ #
25
+ # The comparison operators <code><</code>, <code>></code>, <code><=</code>, and
26
+ # <code>>=</code> are implemented as shorthand for the
27
+ # {proper_,}{subset?,superset?} methods. The <code><=></code> operator reflects
28
+ # this order, or returns `nil` for sets that both have distinct elements
29
+ # (<code>{x, y}</code> vs. <code>{x, z}</code> for example).
30
+ #
24
31
  # ## Example
25
- # require 'set'
26
- # s1 = Set[1, 2] #=> #<Set: {1, 2}>
27
- # s2 = [1, 2].to_set #=> #<Set: {1, 2}>
28
- # s1 == s2 #=> true
29
- # s1.add("foo") #=> #<Set: {1, 2, "foo"}>
30
- # s1.merge([2, 6]) #=> #<Set: {1, 2, "foo", 6}>
31
- # s1.subset?(s2) #=> false
32
- # s2.subset?(s1) #=> true
32
+ #
33
+ # s1 = Set[1, 2] #=> Set[1, 2]
34
+ # s2 = [1, 2].to_set #=> Set[1, 2]
35
+ # s1 == s2 #=> true
36
+ # s1.add("foo") #=> Set[1, 2, "foo"]
37
+ # s1.merge([2, 6]) #=> Set[1, 2, "foo", 6]
38
+ # s1.subset?(s2) #=> false
39
+ # s2.subset?(s1) #=> true
33
40
  #
34
41
  # ## Contact
35
- # * Akinori MUSHA <mailto:knu@iDaemons.org> (current maintainer)
36
- # ## What's Here
42
+ #
43
+ # * Akinori MUSHA <knu@iDaemons.org> (current maintainer)
44
+ #
45
+ # ## Inheriting from Set
46
+ #
47
+ # Before Ruby 4.0 (released December 2025), Set had a different, less efficient
48
+ # implementation. It was reimplemented in C, and the behavior of some of the
49
+ # core methods were adjusted.
50
+ #
51
+ # To keep backward compatibility, when a class is inherited from Set, additional
52
+ # module <code>Set::SubclassCompatible</code> is included, which makes the
53
+ # inherited class behavior, as well as internal method names, closer to what it
54
+ # was before Ruby 4.0.
55
+ #
56
+ # It can be easily seen, for example, in the #inspect method behavior:
57
+ #
58
+ # p Set[1, 2, 3]
59
+ # # prints "Set[1, 2, 3]"
60
+ #
61
+ # class MySet < Set
62
+ # end
63
+ # p MySet[1, 2, 3]
64
+ # # prints "#<MySet: {1, 2, 3}>", like it was in Ruby 3.4
65
+ #
66
+ # For new code, if backward compatibility is not necessary, it is recommended to
67
+ # instead inherit from <code>Set::CoreSet</code>, which avoids including the
68
+ # "compatibility" layer:
69
+ #
70
+ # class MyCoreSet < Set::CoreSet
71
+ # end
72
+ # p MyCoreSet[1, 2, 3]
73
+ # # prints "MyCoreSet[1, 2, 3]"
74
+ #
75
+ # ## Set's methods
76
+ #
37
77
  # First, what's elsewhere. Class Set:
78
+ #
38
79
  # * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
39
- # * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here),
40
- # which provides dozens of additional methods.
41
- # In particular, class Set does not have many methods of its own
42
- # for fetching or for iterating.
43
- # Instead, it relies on those in Enumerable.
80
+ # * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
81
+ # provides dozens of additional methods.
82
+ #
83
+ # In particular, class Set does not have many methods of its own for fetching or
84
+ # for iterating. Instead, it relies on those in Enumerable.
85
+ #
44
86
  # Here, class Set provides methods that are useful for:
45
- # * [Creating a Set](#class-Set-label-Methods+for+Creating+a+Set)
46
- # * [Set Operations](#class-Set-label-Methods+for+Set+Operations)
47
- # * [Comparing](#class-Set-label-Methods+for+Comparing)
48
- # * [Querying](#class-Set-label-Methods+for+Querying)
49
- # * [Assigning](#class-Set-label-Methods+for+Assigning)
50
- # * [Deleting](#class-Set-label-Methods+for+Deleting)
51
- # * [Converting](#class-Set-label-Methods+for+Converting)
52
- # * [Iterating](#class-Set-label-Methods+for+Iterating)
53
- # * [And more....](#class-Set-label-Other+Methods)
87
+ #
88
+ # * [Creating a Set](rdoc-ref:Set@Methods+for+Creating+a+Set)
89
+ # * [Set Operations](rdoc-ref:Set@Methods+for+Set+Operations)
90
+ # * [Comparing](rdoc-ref:Set@Methods+for+Comparing)
91
+ # * [Querying](rdoc-ref:Set@Methods+for+Querying)
92
+ # * [Assigning](rdoc-ref:Set@Methods+for+Assigning)
93
+ # * [Deleting](rdoc-ref:Set@Methods+for+Deleting)
94
+ # * [Converting](rdoc-ref:Set@Methods+for+Converting)
95
+ # * [Iterating](rdoc-ref:Set@Methods+for+Iterating)
96
+ # * [And more....](rdoc-ref:Set@Other+Methods)
97
+ #
54
98
  # ### Methods for Creating a Set
55
- # * ::[]:
56
- # Returns a new set containing the given objects.
57
- # * ::new:
58
- # Returns a new set containing either the given objects
59
- # (if no block given) or the return values from the called block
60
- # (if a block given).
99
+ #
100
+ # * ::[]: Returns a new set containing the given objects.
101
+ # * ::new: Returns a new set containing either the given objects (if no block
102
+ # given) or the return values from the called block (if a block given).
103
+ #
61
104
  # ### Methods for Set Operations
62
- # * [|](#method-i-7C) (aliased as #union and #+):
63
- # Returns a new set containing all elements from `self`
64
- # and all elements from a given enumerable (no duplicates).
65
- # * [&](#method-i-26) (aliased as #intersection):
66
- # Returns a new set containing all elements common to `self`
67
- # and a given enumerable.
68
- # * [-](#method-i-2D) (aliased as #difference):
69
- # Returns a copy of `self` with all elements
70
- # in a given enumerable removed.
71
- # * [\^](#method-i-5E):
72
- # Returns a new set containing all elements from `self`
73
- # and a given enumerable except those common to both.
105
+ #
106
+ # * #| (aliased as #union and #+): Returns a new set containing all elements
107
+ # from `self` and all elements from a given enumerable (no duplicates).
108
+ # * #& (aliased as #intersection): Returns a new set containing all elements
109
+ # common to `self` and a given enumerable.
110
+ # * #- (aliased as #difference): Returns a copy of `self` with all elements in
111
+ # a given enumerable removed.
112
+ # * #^: Returns a new set containing all elements from `self` and a given
113
+ # enumerable except those common to both.
114
+ #
74
115
  # ### Methods for Comparing
75
- # * [<=>](#method-i-3C-3D-3E):
76
- # Returns -1, 0, or 1 as `self` is less than, equal to,
77
- # or greater than a given object.
78
- # * [==](#method-i-3D-3D):
79
- # Returns whether `self` and a given enumerable are equal,
80
- # as determined by Object#eql?.
81
- # * #compare_by_identity?:
82
- # Returns whether the set considers only identity
83
- # when comparing elements.
116
+ #
117
+ # * #<=>: Returns -1, 0, or 1 as `self` is less than, equal to, or greater
118
+ # than a given object.
119
+ # * #==: Returns whether `self` and a given enumerable are equal, as
120
+ # determined by Object#eql?.
121
+ # * #compare_by_identity?: Returns whether the set considers only identity
122
+ # when comparing elements.
123
+ #
84
124
  # ### Methods for Querying
85
- # * #length (aliased as #size):
86
- # Returns the count of elements.
87
- # * #empty?:
88
- # Returns whether the set has no elements.
89
- # * #include? (aliased as #member? and #===):
90
- # Returns whether a given object is an element in the set.
91
- # * #subset? (aliased as [<=](#method-i-3C-3D)):
92
- # Returns whether a given object is a subset of the set.
93
- # * #proper_subset? (aliased as [<](#method-i-3C)):
94
- # Returns whether a given enumerable is a proper subset of the set.
95
- # * #superset? (aliased as [>=](#method-i-3E-3D)]):
96
- # Returns whether a given enumerable is a superset of the set.
97
- # * #proper_superset? (aliased as [>](#method-i-3E)):
98
- # Returns whether a given enumerable is a proper superset of the set.
99
- # * #disjoint?:
100
- # Returns `true` if the set and a given enumerable
101
- # have no common elements, `false` otherwise.
102
- # * #intersect?:
103
- # Returns `true` if the set and a given enumerable:
104
- # have any common elements, `false` otherwise.
105
- # * #compare_by_identity?:
106
- # Returns whether the set considers only identity
107
- # when comparing elements.
125
+ #
126
+ # * #length (aliased as #size): Returns the count of elements.
127
+ # * #empty?: Returns whether the set has no elements.
128
+ # * #include? (aliased as #member? and #===): Returns whether a given object
129
+ # is an element in the set.
130
+ # * #subset? (aliased as #<=): Returns whether a given object is a subset of
131
+ # the set.
132
+ # * #proper_subset? (aliased as #<): Returns whether a given enumerable is a
133
+ # proper subset of the set.
134
+ # * #superset? (aliased as #>=): Returns whether a given enumerable is a
135
+ # superset of the set.
136
+ # * #proper_superset? (aliased as #>): Returns whether a given enumerable is a
137
+ # proper superset of the set.
138
+ # * #disjoint?: Returns `true` if the set and a given enumerable have no
139
+ # common elements, `false` otherwise.
140
+ # * #intersect?: Returns `true` if the set and a given enumerable: have any
141
+ # common elements, `false` otherwise.
142
+ # * #compare_by_identity?: Returns whether the set considers only identity
143
+ # when comparing elements.
144
+ #
108
145
  # ### Methods for Assigning
109
- # * #add (aliased as #<<):
110
- # Adds a given object to the set; returns `self`.
111
- # * #add?:
112
- # If the given object is not an element in the set,
113
- # adds it and returns `self`; otherwise, returns `nil`.
114
- # * #merge:
115
- # Merges the elements of each given enumerable object to the set; returns
116
- # `self`.
117
- # * #replace:
118
- # Replaces the contents of the set with the contents
119
- # of a given enumerable.
146
+ #
147
+ # * #add (aliased as #<<): Adds a given object to the set; returns `self`.
148
+ # * #add?: If the given object is not an element in the set, adds it and
149
+ # returns `self`; otherwise, returns `nil`.
150
+ # * #merge: Merges the elements of each given enumerable object to the set;
151
+ # returns `self`.
152
+ # * #replace: Replaces the contents of the set with the contents of a given
153
+ # enumerable.
154
+ #
120
155
  # ### Methods for Deleting
121
- # * #clear:
122
- # Removes all elements in the set; returns `self`.
123
- # * #delete:
124
- # Removes a given object from the set; returns `self`.
125
- # * #delete?:
126
- # If the given object is an element in the set,
127
- # removes it and returns `self`; otherwise, returns `nil`.
128
- # * #subtract:
129
- # Removes each given object from the set; returns `self`.
156
+ #
157
+ # * #clear: Removes all elements in the set; returns `self`.
158
+ # * #delete: Removes a given object from the set; returns `self`.
159
+ # * #delete?: If the given object is an element in the set, removes it and
160
+ # returns `self`; otherwise, returns `nil`.
161
+ # * #subtract: Removes each given object from the set; returns `self`.
130
162
  # * #delete_if - Removes elements specified by a given block.
131
- # * #select! (aliased as #filter!):
132
- # Removes elements not specified by a given block.
133
- # * #keep_if:
134
- # Removes elements not specified by a given block.
135
- # * #reject!
136
- # Removes elements specified by a given block.
163
+ # * #select! (aliased as #filter!): Removes elements not specified by a given
164
+ # block.
165
+ # * #keep_if: Removes elements not specified by a given block.
166
+ # * #reject! Removes elements specified by a given block.
167
+ #
137
168
  # ### Methods for Converting
138
- # * #classify:
139
- # Returns a hash that classifies the elements,
140
- # as determined by the given block.
141
- # * #collect! (aliased as #map!):
142
- # Replaces each element with a block return-value.
143
- # * #divide:
144
- # Returns a hash that classifies the elements,
145
- # as determined by the given block;
146
- # differs from #classify in that the block may accept
147
- # either one or two arguments.
148
- # * #flatten:
149
- # Returns a new set that is a recursive flattening of `self`.
150
- # #flatten!:
151
- # Replaces each nested set in `self` with the elements from that set.
152
- # * #inspect (aliased as #to_s):
153
- # Returns a string displaying the elements.
154
- # * #join:
155
- # Returns a string containing all elements, converted to strings
156
- # as needed, and joined by the given record separator.
157
- # * #to_a:
158
- # Returns an array containing all set elements.
159
- # * #to_set:
160
- # Returns `self` if given no arguments and no block;
161
- # with a block given, returns a new set consisting of block
162
- # return values.
169
+ #
170
+ # * #classify: Returns a hash that classifies the elements, as determined by
171
+ # the given block.
172
+ # * #collect! (aliased as #map!): Replaces each element with a block
173
+ # return-value.
174
+ # * #divide: Returns a hash that classifies the elements, as determined by the
175
+ # given block; differs from #classify in that the block may accept either
176
+ # one or two arguments.
177
+ # * #flatten: Returns a new set that is a recursive flattening of `self`.
178
+ # * #flatten!: Replaces each nested set in `self` with the elements from that
179
+ # set.
180
+ # * #inspect (aliased as #to_s): Returns a string displaying the elements.
181
+ # * #join: Returns a string containing all elements, converted to strings as
182
+ # needed, and joined by the given record separator.
183
+ # * #to_a: Returns an array containing all set elements.
184
+ # * #to_set: Returns `self` if given no arguments and no block; with a block
185
+ # given, returns a new set consisting of block return values.
186
+ #
163
187
  # ### Methods for Iterating
164
- # * #each:
165
- # Calls the block with each successive element; returns `self`.
188
+ #
189
+ # * #each: Calls the block with each successive element; returns `self`.
190
+ #
166
191
  # ### Other Methods
167
- # * #reset:
168
- # Resets the internal state; useful if an object
169
- # has been modified while an element in the set.
192
+ #
193
+ # * #reset: Resets the internal state; useful if an object has been modified
194
+ # while an element in the set.
170
195
  #
171
196
  class Set[unchecked out A]
172
197
  include Enumerable[A]
173
198
 
174
199
  # <!--
175
- # rdoc-file=lib/set.rb
176
- # - new(enum = nil) { |o| ... }
200
+ # rdoc-file=set.c
201
+ # - Set.new -> new_set
202
+ # - Set.new(enum) -> new_set
203
+ # - Set.new(enum) { |elem| ... } -> new_set
177
204
  # -->
178
- # Creates a new set containing the elements of the given enumerable
179
- # object.
180
- # If a block is given, the elements of enum are preprocessed by the
181
- # given block.
182
- # Set.new([1, 2]) #=> #<Set: {1, 2}>
183
- # Set.new([1, 2, 1]) #=> #<Set: {1, 2}>
184
- # Set.new([1, 'c', :s]) #=> #<Set: {1, "c", :s}>
185
- # Set.new(1..5) #=> #<Set: {1, 2, 3, 4, 5}>
186
- # Set.new([1, 2, 3]) { |x| x * x } #=> #<Set: {1, 4, 9}>
205
+ # Creates a new set containing the elements of the given enumerable object.
206
+ #
207
+ # If a block is given, the elements of enum are preprocessed by the given block.
208
+ #
209
+ # Set.new([1, 2]) #=> Set[1, 2]
210
+ # Set.new([1, 2, 1]) #=> Set[1, 2]
211
+ # Set.new([1, 'c', :s]) #=> Set[1, "c", :s]
212
+ # Set.new(1..5) #=> Set[1, 2, 3, 4, 5]
213
+ # Set.new([1, 2, 3]) { |x| x * x } #=> Set[1, 4, 9]
187
214
  #
188
215
  def initialize: (_Each[A]) -> untyped
189
216
  | [X] (_Each[X]) { (X) -> A } -> untyped
190
217
  | (?nil) -> untyped
191
218
 
192
219
  # <!--
193
- # rdoc-file=lib/set.rb
194
- # - [](*ary)
220
+ # rdoc-file=set.c
221
+ # - Set[*objects] -> new_set
195
222
  # -->
196
- # Creates a new set containing the given objects.
197
- # Set[1, 2] # => #<Set: {1, 2}>
198
- # Set[1, 2, 1] # => #<Set: {1, 2}>
199
- # Set[1, 'c', :s] # => #<Set: {1, "c", :s}>
223
+ # Returns a new Set object populated with the given objects, See Set::new.
200
224
  #
201
225
  def self.[]: [X] (*X) -> Set[X]
202
226
 
203
227
  # <!--
204
- # rdoc-file=lib/set.rb
205
- # - &(enum)
228
+ # rdoc-file=set.c
229
+ # - set & enum -> new_set
206
230
  # -->
207
- # Returns a new set containing elements common to the set and the
208
- # given enumerable object.
209
- # Set[1, 3, 5] & Set[3, 2, 1] #=> #<Set: {3, 1}>
210
- # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
231
+ # Returns a new set containing elements common to the set and the given
232
+ # enumerable object.
233
+ #
234
+ # Set[1, 3, 5] & Set[3, 2, 1] #=> Set[3, 1]
235
+ # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> Set["a", "b"]
211
236
  #
212
237
  def &: (_Each[A]) -> self
213
238
 
214
- # <!--
215
- # rdoc-file=lib/set.rb
216
- # - intersection(enum)
217
- # -->
239
+ # <!-- rdoc-file=set.c -->
240
+ # Returns a new set containing elements common to the set and the given
241
+ # enumerable object.
242
+ #
243
+ # Set[1, 3, 5] & Set[3, 2, 1] #=> Set[3, 1]
244
+ # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> Set["a", "b"]
218
245
  #
219
246
  alias intersection &
220
247
 
221
248
  # <!--
222
- # rdoc-file=lib/set.rb
223
- # - |(enum)
249
+ # rdoc-file=set.c
250
+ # - set | enum -> new_set
224
251
  # -->
225
- # Returns a new set built by merging the set and the elements of the
226
- # given enumerable object.
227
- # Set[1, 2, 3] | Set[2, 4, 5] #=> #<Set: {1, 2, 3, 4, 5}>
228
- # Set[1, 5, 'z'] | (1..6) #=> #<Set: {1, 5, "z", 2, 3, 4, 6}>
252
+ # Returns a new set built by merging the set and the elements of the given
253
+ # enumerable object.
254
+ #
255
+ # Set[1, 2, 3] | Set[2, 4, 5] #=> Set[1, 2, 3, 4, 5]
256
+ # Set[1, 5, 'z'] | (1..6) #=> Set[1, 5, "z", 2, 3, 4, 6]
229
257
  #
230
258
  def |: (_Each[A]) -> self
231
259
 
232
- # <!--
233
- # rdoc-file=lib/set.rb
234
- # - union(enum)
235
- # -->
260
+ # <!-- rdoc-file=set.c -->
261
+ # Returns a new set built by merging the set and the elements of the given
262
+ # enumerable object.
263
+ #
264
+ # Set[1, 2, 3] | Set[2, 4, 5] #=> Set[1, 2, 3, 4, 5]
265
+ # Set[1, 5, 'z'] | (1..6) #=> Set[1, 5, "z", 2, 3, 4, 6]
236
266
  #
237
267
  alias union |
238
268
 
239
- # <!--
240
- # rdoc-file=lib/set.rb
241
- # - +(enum)
242
- # -->
269
+ # <!-- rdoc-file=set.c -->
270
+ # Returns a new set built by merging the set and the elements of the given
271
+ # enumerable object.
272
+ #
273
+ # Set[1, 2, 3] | Set[2, 4, 5] #=> Set[1, 2, 3, 4, 5]
274
+ # Set[1, 5, 'z'] | (1..6) #=> Set[1, 5, "z", 2, 3, 4, 6]
243
275
  #
244
276
  alias + |
245
277
 
246
278
  # <!--
247
- # rdoc-file=lib/set.rb
248
- # - -(enum)
279
+ # rdoc-file=set.c
280
+ # - set - enum -> new_set
249
281
  # -->
250
- # Returns a new set built by duplicating the set, removing every
251
- # element that appears in the given enumerable object.
252
- # Set[1, 3, 5] - Set[1, 5] #=> #<Set: {3}>
253
- # Set['a', 'b', 'z'] - ['a', 'c'] #=> #<Set: {"b", "z"}>
282
+ # Returns a new set built by duplicating the set, removing every element that
283
+ # appears in the given enumerable object.
284
+ #
285
+ # Set[1, 3, 5] - Set[1, 5] #=> Set[3]
286
+ # Set['a', 'b', 'z'] - ['a', 'c'] #=> Set["b", "z"]
254
287
  #
255
288
  def -: (_Each[A]) -> self
256
289
 
257
- # <!--
258
- # rdoc-file=lib/set.rb
259
- # - difference(enum)
260
- # -->
290
+ # <!-- rdoc-file=set.c -->
291
+ # Returns a new set built by duplicating the set, removing every element that
292
+ # appears in the given enumerable object.
293
+ #
294
+ # Set[1, 3, 5] - Set[1, 5] #=> Set[3]
295
+ # Set['a', 'b', 'z'] - ['a', 'c'] #=> Set["b", "z"]
261
296
  #
262
297
  alias difference -
263
298
 
264
299
  # <!--
265
- # rdoc-file=lib/set.rb
266
- # - add(o)
300
+ # rdoc-file=set.c
301
+ # - add(obj) -> self
267
302
  # -->
268
- # Adds the given object to the set and returns self. Use `merge` to
269
- # add many elements at once.
270
- # Set[1, 2].add(3) #=> #<Set: {1, 2, 3}>
271
- # Set[1, 2].add([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
272
- # Set[1, 2].add(2) #=> #<Set: {1, 2}>
303
+ # Adds the given object to the set and returns self. Use Set#merge to add many
304
+ # elements at once.
305
+ #
306
+ # Set[1, 2].add(3) #=> Set[1, 2, 3]
307
+ # Set[1, 2].add([3, 4]) #=> Set[1, 2, [3, 4]]
308
+ # Set[1, 2].add(2) #=> Set[1, 2]
273
309
  #
274
310
  def add: (A) -> self
275
311
 
276
- # <!--
277
- # rdoc-file=lib/set.rb
278
- # - <<(o)
279
- # -->
312
+ # <!-- rdoc-file=set.c -->
313
+ # Adds the given object to the set and returns self. Use Set#merge to add many
314
+ # elements at once.
315
+ #
316
+ # Set[1, 2].add(3) #=> Set[1, 2, 3]
317
+ # Set[1, 2].add([3, 4]) #=> Set[1, 2, [3, 4]]
318
+ # Set[1, 2].add(2) #=> Set[1, 2]
280
319
  #
281
320
  alias << add
282
321
 
283
322
  # <!--
284
- # rdoc-file=lib/set.rb
285
- # - add?(o)
323
+ # rdoc-file=set.c
324
+ # - add?(obj) -> self or nil
286
325
  # -->
287
- # Adds the given object to the set and returns self. If the
288
- # object is already in the set, returns nil.
289
- # Set[1, 2].add?(3) #=> #<Set: {1, 2, 3}>
290
- # Set[1, 2].add?([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
326
+ # Adds the given object to the set and returns self. If the object is already in
327
+ # the set, returns nil.
328
+ #
329
+ # Set[1, 2].add?(3) #=> Set[1, 2, 3]
330
+ # Set[1, 2].add?([3, 4]) #=> Set[1, 2, [3, 4]]
291
331
  # Set[1, 2].add?(2) #=> nil
292
332
  #
293
333
  def add?: (A) -> self?
294
334
 
295
335
  # <!--
296
- # rdoc-file=lib/set.rb
297
- # - include?(o)
336
+ # rdoc-file=set.c
337
+ # - include?(item) -> true or false
298
338
  # -->
299
- # Returns true if the set contains the given object.
300
- # Note that `include?` and `member?` do not test member
301
- # equality using `==` as do other Enumerables.
339
+ # Returns true if the set contains the given object:
340
+ #
341
+ # Set[1, 2, 3].include? 2 #=> true
342
+ # Set[1, 2, 3].include? 4 #=> false
343
+ #
344
+ # Note that <code>include?</code> and <code>member?</code> do not test member
345
+ # equality using <code>==</code> as do other Enumerables.
346
+ #
347
+ # This is aliased to #===, so it is usable in `case` expressions:
348
+ #
349
+ # case :apple
350
+ # when Set[:potato, :carrot]
351
+ # "vegetable"
352
+ # when Set[:apple, :banana]
353
+ # "fruit"
354
+ # end
355
+ # # => "fruit"
356
+ #
302
357
  # See also Enumerable#include?
303
358
  #
304
- def include?: (A) -> bool
359
+ def include?: (Hash::_Key) -> bool
305
360
 
306
- # <!--
307
- # rdoc-file=lib/set.rb
308
- # - member?(o)
309
- # -->
361
+ # <!-- rdoc-file=set.c -->
362
+ # Returns true if the set contains the given object:
363
+ #
364
+ # Set[1, 2, 3].include? 2 #=> true
365
+ # Set[1, 2, 3].include? 4 #=> false
366
+ #
367
+ # Note that <code>include?</code> and <code>member?</code> do not test member
368
+ # equality using <code>==</code> as do other Enumerables.
369
+ #
370
+ # This is aliased to #===, so it is usable in `case` expressions:
371
+ #
372
+ # case :apple
373
+ # when Set[:potato, :carrot]
374
+ # "vegetable"
375
+ # when Set[:apple, :banana]
376
+ # "fruit"
377
+ # end
378
+ # # => "fruit"
379
+ #
380
+ # See also Enumerable#include?
310
381
  #
311
382
  alias member? include?
312
383
 
313
384
  # <!--
314
- # rdoc-file=lib/set.rb
315
- # - ^(enum)
385
+ # rdoc-file=set.c
386
+ # - set ^ enum -> new_set
316
387
  # -->
317
- # Returns a new set containing elements exclusive between the set
318
- # and the given enumerable object. `(set ^ enum)` is equivalent to
319
- # `((set | enum) - (set & enum))`.
320
- # Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
321
- # Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
388
+ # Returns a new set containing elements exclusive between the set and the given
389
+ # enumerable object. <code>(set ^ enum)</code> is equivalent to <code>((set |
390
+ # enum) - (set & enum))</code>.
391
+ #
392
+ # Set[1, 2] ^ Set[2, 3] #=> Set[3, 1]
393
+ # Set[1, 'b', 'c'] ^ ['b', 'd'] #=> Set["d", 1, "c"]
322
394
  #
323
395
  def ^: (_Each[A]) -> self
324
396
 
325
397
  # <!--
326
- # rdoc-file=lib/set.rb
327
- # - classify() { |o| ... }
398
+ # rdoc-file=set.c
399
+ # - classify { |o| ... } -> hash
400
+ # - classify -> enumerator
328
401
  # -->
329
- # Classifies the set by the return value of the given block and
330
- # returns a hash of {value => set of elements} pairs. The block is
331
- # called once for each element of the set, passing the element as
332
- # parameter.
333
- # require 'set'
402
+ # Classifies the set by the return value of the given block and returns a hash
403
+ # of {value => set of elements} pairs. The block is called once for each
404
+ # element of the set, passing the element as parameter.
405
+ #
334
406
  # files = Set.new(Dir.glob("*.rb"))
335
407
  # hash = files.classify { |f| File.mtime(f).year }
336
- # hash #=> {2000=>#<Set: {"a.rb", "b.rb"}>,
337
- # # 2001=>#<Set: {"c.rb", "d.rb", "e.rb"}>,
338
- # # 2002=>#<Set: {"f.rb"}>}
408
+ # hash #=> {2000 => Set["a.rb", "b.rb"],
409
+ # # 2001 => Set["c.rb", "d.rb", "e.rb"],
410
+ # # 2002 => Set["f.rb"]}
339
411
  #
340
412
  # Returns an enumerator if no block is given.
341
413
  #
342
414
  def classify: [X] () { (A) -> X } -> Hash[X, self]
343
415
 
344
416
  # <!--
345
- # rdoc-file=lib/set.rb
346
- # - clear()
417
+ # rdoc-file=set.c
418
+ # - clear -> self
347
419
  # -->
348
420
  # Removes all elements and returns self.
349
- # set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
350
- # set.clear #=> #<Set: {}>
351
- # set #=> #<Set: {}>
421
+ #
422
+ # set = Set[1, 'c', :s] #=> Set[1, "c", :s]
423
+ # set.clear #=> Set[]
424
+ # set #=> Set[]
352
425
  #
353
426
  def clear: () -> self
354
427
 
355
428
  # <!--
356
- # rdoc-file=lib/set.rb
357
- # - collect!() { |o| ... }
429
+ # rdoc-file=set.c
430
+ # - collect! { |o| ... } -> self
431
+ # - collect! -> enumerator
358
432
  # -->
359
- # Replaces the elements with ones returned by `collect()`.
360
- # Returns an enumerator if no block is given.
433
+ # Replaces the elements with ones returned by `collect`. Returns an enumerator
434
+ # if no block is given.
361
435
  #
362
436
  def collect!: () { (A) -> A } -> self
363
437
 
364
- # <!--
365
- # rdoc-file=lib/set.rb
366
- # - map!()
367
- # -->
438
+ # <!-- rdoc-file=set.c -->
439
+ # Replaces the elements with ones returned by `collect`. Returns an enumerator
440
+ # if no block is given.
368
441
  #
369
442
  alias map! collect!
370
443
 
371
444
  # <!--
372
- # rdoc-file=lib/set.rb
373
- # - delete(o)
445
+ # rdoc-file=set.c
446
+ # - delete(obj) -> self
374
447
  # -->
375
- # Deletes the given object from the set and returns self. Use
376
- # `subtract` to delete many items at once.
448
+ # Deletes the given object from the set and returns self. Use subtract to delete
449
+ # many items at once.
377
450
  #
378
451
  def delete: (A) -> self
379
452
 
380
453
  # <!--
381
- # rdoc-file=lib/set.rb
382
- # - delete?(o)
454
+ # rdoc-file=set.c
455
+ # - delete?(obj) -> self or nil
383
456
  # -->
384
- # Deletes the given object from the set and returns self. If the
385
- # object is not in the set, returns nil.
457
+ # Deletes the given object from the set and returns self. If the object is not
458
+ # in the set, returns nil.
386
459
  #
387
460
  def delete?: (A) -> self?
388
461
 
389
462
  # <!--
390
- # rdoc-file=lib/set.rb
391
- # - delete_if(&block)
463
+ # rdoc-file=set.c
464
+ # - delete_if { |o| ... } -> self
465
+ # - delete_if -> enumerator
392
466
  # -->
393
- # Deletes every element of the set for which block evaluates to
394
- # true, and returns self. Returns an enumerator if no block is
395
- # given.
467
+ # Deletes every element of the set for which block evaluates to true, and
468
+ # returns self. Returns an enumerator if no block is given.
396
469
  #
397
470
  def delete_if: () { (A) -> untyped } -> self
398
471
 
399
472
  # <!--
400
- # rdoc-file=lib/set.rb
401
- # - reject!(&block)
473
+ # rdoc-file=set.c
474
+ # - reject! { |o| ... } -> self
475
+ # - reject! -> enumerator
402
476
  # -->
403
- # Equivalent to Set#delete_if, but returns nil if no changes were
404
- # made. Returns an enumerator if no block is given.
477
+ # Equivalent to Set#delete_if, but returns nil if no changes were made. Returns
478
+ # an enumerator if no block is given.
405
479
  #
406
480
  def reject!: () { (A) -> untyped } -> self?
407
481
 
408
482
  # <!--
409
- # rdoc-file=lib/set.rb
410
- # - compare_by_identity()
483
+ # rdoc-file=set.c
484
+ # - compare_by_identity -> self
411
485
  # -->
412
- # Makes the set compare its elements by their identity and returns
413
- # self. This method may not be supported by all subclasses of Set.
486
+ # Makes the set compare its elements by their identity and returns self.
414
487
  #
415
488
  def compare_by_identity: () -> self
416
489
 
417
490
  # <!--
418
- # rdoc-file=lib/set.rb
419
- # - disjoint?(set)
491
+ # rdoc-file=set.c
492
+ # - compare_by_identity? -> true or false
420
493
  # -->
421
- # Returns true if the set and the given enumerable have
422
- # no element in common. This method is the opposite of `intersect?`.
494
+ # Returns true if the set will compare its elements by their identity. Also see
495
+ # Set#compare_by_identity.
496
+ #
497
+ def compare_by_identity?: () -> bool
498
+
499
+ # <!--
500
+ # rdoc-file=set.c
501
+ # - disjoint?(set) -> true or false
502
+ # -->
503
+ # Returns true if the set and the given enumerable have no element in common.
504
+ # This method is the opposite of <code>intersect?</code>.
505
+ #
423
506
  # Set[1, 2, 3].disjoint? Set[3, 4] #=> false
424
507
  # Set[1, 2, 3].disjoint? Set[4, 5] #=> true
425
508
  # Set[1, 2, 3].disjoint? [3, 4] #=> false
@@ -428,21 +511,24 @@ class Set[unchecked out A]
428
511
  def disjoint?: (Set[A] | Enumerable[A]) -> bool
429
512
 
430
513
  # <!--
431
- # rdoc-file=lib/set.rb
432
- # - divide(&func)
514
+ # rdoc-file=set.c
515
+ # - divide { |o1, o2| ... } -> set
516
+ # - divide { |o| ... } -> set
517
+ # - divide -> enumerator
433
518
  # -->
434
- # Divides the set into a set of subsets according to the commonality
435
- # defined by the given block.
436
- # If the arity of the block is 2, elements o1 and o2 are in common
437
- # if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are
438
- # in common if block.call(o1) == block.call(o2).
439
- # require 'set'
519
+ # Divides the set into a set of subsets according to the commonality defined by
520
+ # the given block.
521
+ #
522
+ # If the arity of the block is 2, elements o1 and o2 are in common if both
523
+ # block.call(o1, o2) and block.call(o2, o1) are true. Otherwise, elements o1 and
524
+ # o2 are in common if block.call(o1) == block.call(o2).
525
+ #
440
526
  # numbers = Set[1, 3, 4, 6, 9, 10, 11]
441
527
  # set = numbers.divide { |i,j| (i - j).abs == 1 }
442
- # set #=> #<Set: {#<Set: {1}>,
443
- # # #<Set: {11, 9, 10}>,
444
- # # #<Set: {3, 4}>,
445
- # # #<Set: {6}>}>
528
+ # set #=> Set[Set[1],
529
+ # # Set[3, 4],
530
+ # # Set[6],
531
+ # # Set[9, 10, 11]]
446
532
  #
447
533
  # Returns an enumerator if no block is given.
448
534
  #
@@ -450,39 +536,49 @@ class Set[unchecked out A]
450
536
  | () { (A) -> Hash::_Key } -> Set[self]
451
537
 
452
538
  # <!--
453
- # rdoc-file=lib/set.rb
454
- # - each(&block)
539
+ # rdoc-file=set.c
540
+ # - each { |o| ... } -> self
541
+ # - each -> enumerator
455
542
  # -->
456
- # Calls the given block once for each element in the set, passing
457
- # the element as parameter. Returns an enumerator if no block is
458
- # given.
543
+ # Calls the given block once for each element in the set, passing the element as
544
+ # parameter. Returns an enumerator if no block is given.
459
545
  #
460
546
  def each: () { (A) -> void } -> self
461
547
  | () -> Enumerator[A, self]
462
548
 
463
549
  # <!--
464
- # rdoc-file=lib/set.rb
465
- # - empty?()
550
+ # rdoc-file=set.c
551
+ # - empty? -> true or false
466
552
  # -->
467
553
  # Returns true if the set contains no elements.
468
554
  #
469
555
  def empty?: () -> bool
470
556
 
471
557
  # <!--
472
- # rdoc-file=lib/set.rb
473
- # - flatten()
558
+ # rdoc-file=set.c
559
+ # - flatten -> set
474
560
  # -->
475
- # Returns a new set that is a copy of the set, flattening each
476
- # containing set recursively.
561
+ # Returns a new set that is a copy of the set, flattening each containing set
562
+ # recursively.
477
563
  #
478
564
  def flatten: () -> Set[untyped]
479
565
 
480
566
  # <!--
481
- # rdoc-file=lib/set.rb
482
- # - intersect?(set)
567
+ # rdoc-file=set.c
568
+ # - flatten! -> self
569
+ # -->
570
+ # Equivalent to Set#flatten, but replaces the receiver with the result in place.
571
+ # Returns nil if no modifications were made.
572
+ #
573
+ def flatten!: () -> self?
574
+
575
+ # <!--
576
+ # rdoc-file=set.c
577
+ # - intersect?(set) -> true or false
483
578
  # -->
484
- # Returns true if the set and the given enumerable have at least one
485
- # element in common.
579
+ # Returns true if the set and the given enumerable have at least one element in
580
+ # common.
581
+ #
486
582
  # Set[1, 2, 3].intersect? Set[4, 5] #=> false
487
583
  # Set[1, 2, 3].intersect? Set[3, 4] #=> true
488
584
  # Set[1, 2, 3].intersect? 4..5 #=> false
@@ -491,130 +587,164 @@ class Set[unchecked out A]
491
587
  def intersect?: (Set[A] | Enumerable[A]) -> bool
492
588
 
493
589
  # <!--
494
- # rdoc-file=lib/set.rb
495
- # - keep_if(&block)
590
+ # rdoc-file=set.c
591
+ # - keep_if { |o| ... } -> self
592
+ # - keep_if -> enumerator
496
593
  # -->
497
- # Deletes every element of the set for which block evaluates to
498
- # false, and returns self. Returns an enumerator if no block is
499
- # given.
594
+ # Deletes every element of the set for which block evaluates to false, and
595
+ # returns self. Returns an enumerator if no block is given.
500
596
  #
501
597
  def keep_if: () { (A) -> untyped } -> self
502
598
 
503
599
  # <!--
504
- # rdoc-file=lib/set.rb
505
- # - size()
600
+ # rdoc-file=set.c
601
+ # - size -> integer
506
602
  # -->
507
603
  # Returns the number of elements.
508
604
  #
509
605
  def size: () -> Integer
510
606
 
511
- # <!--
512
- # rdoc-file=lib/set.rb
513
- # - length()
514
- # -->
607
+ # <!-- rdoc-file=set.c -->
608
+ # Returns the number of elements.
515
609
  #
516
610
  alias length size
517
611
 
518
612
  # <!--
519
- # rdoc-file=lib/set.rb
520
- # - merge(*enums, **nil)
613
+ # rdoc-file=set.c
614
+ # - merge(*enums, **nil) -> self
521
615
  # -->
522
- # Merges the elements of the given enumerable objects to the set and
523
- # returns self.
616
+ # Merges the elements of the given enumerable objects to the set and returns
617
+ # self.
524
618
  #
525
619
  def merge: (*_Each[A]) -> self
526
620
 
527
621
  # <!--
528
- # rdoc-file=lib/set.rb
529
- # - subset?(set)
622
+ # rdoc-file=set.c
623
+ # - subset?(set) -> true or false
530
624
  # -->
531
625
  # Returns true if the set is a subset of the given set.
532
626
  #
533
627
  def subset?: (self) -> bool
534
628
 
629
+ # <!-- rdoc-file=set.c -->
630
+ # Returns true if the set is a subset of the given set.
631
+ #
632
+ alias <= subset?
633
+
535
634
  # <!--
536
- # rdoc-file=lib/set.rb
537
- # - proper_subset?(set)
635
+ # rdoc-file=set.c
636
+ # - proper_subset?(set) -> true or false
538
637
  # -->
539
638
  # Returns true if the set is a proper subset of the given set.
540
639
  #
541
640
  def proper_subset?: (self) -> bool
542
641
 
642
+ # <!-- rdoc-file=set.c -->
643
+ # Returns true if the set is a proper subset of the given set.
644
+ #
645
+ alias < proper_subset?
646
+
543
647
  # <!--
544
- # rdoc-file=lib/set.rb
545
- # - superset?(set)
648
+ # rdoc-file=set.c
649
+ # - superset?(set) -> true or false
546
650
  # -->
547
651
  # Returns true if the set is a superset of the given set.
548
652
  #
549
653
  def superset?: (self) -> bool
550
654
 
655
+ # <!-- rdoc-file=set.c -->
656
+ # Returns true if the set is a superset of the given set.
657
+ #
658
+ alias >= superset?
659
+
551
660
  # <!--
552
- # rdoc-file=lib/set.rb
553
- # - proper_superset?(set)
661
+ # rdoc-file=set.c
662
+ # - proper_superset?(set) -> true or false
554
663
  # -->
555
664
  # Returns true if the set is a proper superset of the given set.
556
665
  #
557
666
  def proper_superset?: (self) -> bool
558
667
 
668
+ # <!-- rdoc-file=set.c -->
669
+ # Returns true if the set is a proper superset of the given set.
670
+ #
671
+ alias > proper_superset?
672
+
559
673
  # <!--
560
- # rdoc-file=lib/set.rb
561
- # - replace(enum)
674
+ # rdoc-file=set.c
675
+ # - replace(enum) -> self
562
676
  # -->
563
- # Replaces the contents of the set with the contents of the given
564
- # enumerable object and returns self.
565
- # set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
566
- # set.replace([1, 2]) #=> #<Set: {1, 2}>
567
- # set #=> #<Set: {1, 2}>
677
+ # Replaces the contents of the set with the contents of the given enumerable
678
+ # object and returns self.
679
+ #
680
+ # set = Set[1, 'c', :s] #=> Set[1, "c", :s]
681
+ # set.replace([1, 2]) #=> Set[1, 2]
682
+ # set #=> Set[1, 2]
568
683
  #
569
684
  def replace: (_Each[A]) -> self
570
685
 
571
686
  # <!--
572
- # rdoc-file=lib/set.rb
573
- # - reset()
687
+ # rdoc-file=set.c
688
+ # - reset -> self
574
689
  # -->
575
- # Resets the internal state after modification to existing elements
576
- # and returns self.
577
- # Elements will be reindexed and deduplicated.
690
+ # Resets the internal state after modification to existing elements and returns
691
+ # self. Elements will be reindexed and deduplicated.
578
692
  #
579
693
  def reset: () -> self
580
694
 
581
695
  # <!--
582
- # rdoc-file=lib/set.rb
583
- # - select!(&block)
696
+ # rdoc-file=set.c
697
+ # - select! { |o| ... } -> self
698
+ # - select! -> enumerator
584
699
  # -->
585
- # Equivalent to Set#keep_if, but returns nil if no changes were
586
- # made. Returns an enumerator if no block is given.
700
+ # Equivalent to Set#keep_if, but returns nil if no changes were made. Returns an
701
+ # enumerator if no block is given.
587
702
  #
588
703
  def select!: () { (A) -> untyped } -> self?
589
704
 
705
+ # <!-- rdoc-file=set.c -->
706
+ # Equivalent to Set#keep_if, but returns nil if no changes were made. Returns an
707
+ # enumerator if no block is given.
708
+ #
709
+ alias filter! select!
710
+
590
711
  # <!--
591
- # rdoc-file=lib/set.rb
592
- # - subtract(enum)
712
+ # rdoc-file=set.c
713
+ # - subtract(enum) -> self
593
714
  # -->
594
- # Deletes every element that appears in the given enumerable object
595
- # and returns self.
715
+ # Deletes every element that appears in the given enumerable object and returns
716
+ # self.
596
717
  #
597
718
  def subtract: (_Each[A]) -> self
598
719
 
599
720
  # <!--
600
- # rdoc-file=lib/set.rb
601
- # - to_a()
721
+ # rdoc-file=set.c
722
+ # - to_a -> array
602
723
  # -->
603
724
  # Returns an array containing all elements in the set.
725
+ #
604
726
  # Set[1, 2].to_a #=> [1, 2]
605
727
  # Set[1, 'c', :s].to_a #=> [1, "c", :s]
606
728
  #
607
729
  def to_a: () -> Array[A]
730
+
731
+ # <!--
732
+ # rdoc-file=set.c
733
+ # - join(separator=nil)-> new_string
734
+ # -->
735
+ # Returns a string created by converting each element of the set to a string.
736
+ #
737
+ def join: (?string separator) -> String
608
738
  end
609
739
 
610
740
  %a{annotate:rdoc:skip}
611
741
  module Enumerable[unchecked out Elem]
612
742
  # <!--
613
- # rdoc-file=lib/set.rb
614
- # - to_set(klass = Set, *args, &block)
743
+ # rdoc-file=prelude.rb
744
+ # - to_set(*args, &block)
615
745
  # -->
616
- # Makes a set from the enumerable object with given arguments.
617
- # Needs to `require "set"` to use this method.
746
+ # Makes a set from the enumerable object with given arguments. Passing arguments
747
+ # to this method is deprecated.
618
748
  #
619
749
  def to_set: () -> Set[Elem]
620
750
  | [T] () { (Elem) -> T } -> Set[T]