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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +18 -11
- data/.github/workflows/comments.yml +5 -3
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/ruby.yml +27 -34
- data/.github/workflows/rust.yml +95 -0
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +323 -0
- data/README.md +1 -1
- data/Rakefile +43 -33
- data/Steepfile +1 -0
- data/config.yml +426 -24
- data/core/array.rbs +307 -227
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +55 -34
- data/core/complex.rbs +104 -78
- data/core/dir.rbs +61 -49
- data/core/encoding.rbs +12 -15
- data/core/enumerable.rbs +179 -87
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +65 -2
- data/core/errno.rbs +11 -2
- data/core/errors.rbs +58 -29
- data/core/exception.rbs +13 -13
- data/core/fiber.rbs +74 -54
- data/core/file.rbs +280 -177
- data/core/file_test.rbs +3 -3
- data/core/float.rbs +257 -92
- data/core/gc.rbs +425 -281
- data/core/hash.rbs +1045 -739
- data/core/integer.rbs +135 -137
- data/core/io/buffer.rbs +53 -42
- data/core/io/wait.rbs +13 -35
- data/core/io.rbs +192 -144
- data/core/kernel.rbs +216 -155
- data/core/marshal.rbs +4 -4
- data/core/match_data.rbs +15 -13
- data/core/math.rbs +107 -66
- data/core/method.rbs +69 -33
- data/core/module.rbs +244 -106
- data/core/nil_class.rbs +7 -6
- data/core/numeric.rbs +74 -63
- data/core/object.rbs +9 -11
- data/core/object_space.rbs +30 -23
- data/core/pathname.rbs +1322 -0
- data/core/proc.rbs +95 -58
- data/core/process.rbs +222 -202
- data/core/ractor.rbs +371 -515
- data/core/random.rbs +21 -3
- data/core/range.rbs +159 -57
- data/core/rational.rbs +60 -89
- data/core/rbs/unnamed/argf.rbs +60 -53
- data/core/rbs/unnamed/env_class.rbs +19 -14
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +11 -118
- data/core/regexp.rbs +258 -214
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +38 -34
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +4 -71
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +16 -82
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +490 -360
- data/core/signal.rbs +26 -16
- data/core/string.rbs +3234 -1285
- data/core/struct.rbs +27 -26
- data/core/symbol.rbs +41 -34
- data/core/thread.rbs +135 -67
- data/core/time.rbs +81 -50
- data/core/trace_point.rbs +41 -35
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +24 -16
- data/core/warning.rbs +7 -7
- data/docs/aliases.md +79 -0
- data/docs/collection.md +3 -3
- data/docs/config.md +171 -0
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +576 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +46 -16
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +544 -116
- data/ext/rbs_extension/ast_translation.h +3 -0
- data/ext/rbs_extension/class_constants.c +16 -2
- data/ext/rbs_extension/class_constants.h +8 -0
- data/ext/rbs_extension/extconf.rb +5 -1
- data/ext/rbs_extension/legacy_location.c +33 -56
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +44 -35
- data/include/rbs/ast.h +448 -173
- data/include/rbs/defines.h +27 -0
- data/include/rbs/lexer.h +30 -11
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +6 -6
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/include/rbs.h +8 -0
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +293 -3
- data/lib/rbs/ast/ruby/comment_block.rb +24 -0
- data/lib/rbs/ast/ruby/declarations.rb +198 -3
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/members.rb +532 -22
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +20 -15
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -106
- data/lib/rbs/cli.rb +52 -19
- data/lib/rbs/collection/config/lockfile_generator.rb +14 -2
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +20 -0
- data/lib/rbs/definition_builder.rb +147 -25
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +227 -74
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -18
- data/lib/rbs/inline_parser.rb +342 -6
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/parser_aux.rb +20 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +3 -20
- data/lib/rbs/prototype/runtime.rb +8 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +116 -38
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +19 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +88 -78
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -2
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +4 -3
- data/rust/.gitignore +1 -0
- data/rust/Cargo.lock +378 -0
- data/rust/Cargo.toml +7 -0
- data/rust/ruby-rbs/Cargo.toml +22 -0
- data/rust/ruby-rbs/build.rs +764 -0
- data/rust/ruby-rbs/examples/locations.rs +60 -0
- data/rust/ruby-rbs/src/lib.rs +1 -0
- data/rust/ruby-rbs/src/node/mod.rs +742 -0
- data/rust/ruby-rbs/tests/sanity.rs +47 -0
- data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
- data/rust/ruby-rbs-sys/Cargo.toml +23 -0
- data/rust/ruby-rbs-sys/build.rs +204 -0
- data/rust/ruby-rbs-sys/src/lib.rs +50 -0
- data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
- data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
- data/rust/ruby-rbs-sys/wrapper.h +1 -0
- data/schema/typeParam.json +17 -1
- data/sig/ast/ruby/annotations.rbs +315 -4
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +108 -2
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -1
- data/sig/definition_builder.rbs +2 -0
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -14
- data/sig/inline_parser.rbs +39 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -1
- data/sig/method_builder.rbs +3 -1
- data/sig/parser.rbs +31 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +35 -7
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/types.rbs +6 -7
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +410 -153
- data/src/lexer.c +1392 -1313
- data/src/lexer.re +3 -0
- data/src/lexstate.c +58 -37
- data/src/location.c +8 -48
- data/src/parser.c +977 -516
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -71
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -14
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +7 -4
- data/stdlib/date/0/date.rbs +92 -79
- data/stdlib/date/0/date_time.rbs +25 -24
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +748 -347
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +158 -139
- data/stdlib/forwardable/0/forwardable.rbs +13 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +217 -136
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +162 -134
- data/stdlib/objspace/0/objspace.rbs +17 -34
- data/stdlib/open-uri/0/open-uri.rbs +48 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +475 -357
- data/stdlib/optparse/0/optparse.rbs +26 -17
- data/stdlib/pathname/0/pathname.rbs +11 -1381
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +65 -12
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +22 -19
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +23 -10
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +11 -3
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1177 -85
- data/stdlib/strscan/0/string_scanner.rbs +27 -25
- data/stdlib/tempfile/0/tempfile.rbs +25 -21
- data/stdlib/time/0/time.rbs +8 -6
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +42 -20
- data/stdlib/uri/0/file.rbs +3 -3
- data/stdlib/uri/0/generic.rbs +26 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +6 -6
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +50 -6
data/core/set.rbs
CHANGED
|
@@ -1,425 +1,508 @@
|
|
|
1
|
-
# <!-- rdoc-file=
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# Set is easy to use with Enumerable objects (implementing
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
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
|
-
#
|
|
13
|
-
#
|
|
14
|
-
# * Set assumes that the identity of each element does not change
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
# * When a string is to be stored, a frozen copy of the string is
|
|
18
|
-
#
|
|
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
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
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
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
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
|
-
#
|
|
36
|
-
#
|
|
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
|
-
#
|
|
41
|
-
#
|
|
42
|
-
# for fetching or
|
|
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
|
-
#
|
|
46
|
-
# * [Set
|
|
47
|
-
# * [
|
|
48
|
-
# * [
|
|
49
|
-
# * [
|
|
50
|
-
# * [
|
|
51
|
-
# * [
|
|
52
|
-
# * [
|
|
53
|
-
# * [
|
|
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
|
-
#
|
|
57
|
-
# * ::new:
|
|
58
|
-
#
|
|
59
|
-
#
|
|
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
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
# *
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
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
|
-
#
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
# *
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
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
|
-
#
|
|
86
|
-
#
|
|
87
|
-
# * #empty?:
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
92
|
-
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
97
|
-
#
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
# * #
|
|
103
|
-
#
|
|
104
|
-
#
|
|
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
|
-
#
|
|
110
|
-
#
|
|
111
|
-
# * #add?:
|
|
112
|
-
#
|
|
113
|
-
#
|
|
114
|
-
#
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
#
|
|
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
|
-
#
|
|
122
|
-
#
|
|
123
|
-
# * #delete:
|
|
124
|
-
#
|
|
125
|
-
#
|
|
126
|
-
#
|
|
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
|
-
#
|
|
133
|
-
# * #keep_if:
|
|
134
|
-
#
|
|
135
|
-
#
|
|
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
|
-
#
|
|
139
|
-
#
|
|
140
|
-
#
|
|
141
|
-
# * #collect! (aliased as #map!):
|
|
142
|
-
#
|
|
143
|
-
# * #divide:
|
|
144
|
-
#
|
|
145
|
-
#
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
#
|
|
151
|
-
#
|
|
152
|
-
# * #
|
|
153
|
-
#
|
|
154
|
-
#
|
|
155
|
-
#
|
|
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
|
-
#
|
|
165
|
-
#
|
|
188
|
+
#
|
|
189
|
+
# * #each: Calls the block with each successive element; returns `self`.
|
|
190
|
+
#
|
|
166
191
|
# ### Other Methods
|
|
167
|
-
#
|
|
168
|
-
#
|
|
169
|
-
#
|
|
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=
|
|
176
|
-
# - new
|
|
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
|
-
#
|
|
180
|
-
# If a block is given, the elements of enum are preprocessed by the
|
|
181
|
-
#
|
|
182
|
-
# Set.new([1, 2]) #=>
|
|
183
|
-
# Set.new([1, 2, 1]) #=>
|
|
184
|
-
# Set.new([1, 'c', :s]) #=>
|
|
185
|
-
# Set.new(1..5) #=>
|
|
186
|
-
# Set.new([1, 2, 3]) { |x| x * x } #=>
|
|
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=
|
|
194
|
-
# - []
|
|
220
|
+
# rdoc-file=set.c
|
|
221
|
+
# - Set[*objects] -> new_set
|
|
195
222
|
# -->
|
|
196
|
-
#
|
|
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=
|
|
205
|
-
# - &
|
|
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
|
-
#
|
|
209
|
-
#
|
|
210
|
-
# Set[
|
|
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
|
-
#
|
|
216
|
-
#
|
|
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=
|
|
223
|
-
# - |
|
|
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
|
-
#
|
|
227
|
-
#
|
|
228
|
-
# Set[1,
|
|
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
|
-
#
|
|
234
|
-
#
|
|
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
|
-
#
|
|
241
|
-
#
|
|
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=
|
|
248
|
-
# - -
|
|
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
|
-
#
|
|
252
|
-
#
|
|
253
|
-
# Set[
|
|
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
|
-
#
|
|
259
|
-
#
|
|
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=
|
|
266
|
-
# - add(
|
|
300
|
+
# rdoc-file=set.c
|
|
301
|
+
# - add(obj) -> self
|
|
267
302
|
# -->
|
|
268
|
-
# Adds the given object to the set and returns self. Use
|
|
269
|
-
#
|
|
270
|
-
#
|
|
271
|
-
# Set[1, 2].add(
|
|
272
|
-
# Set[1, 2].add(
|
|
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
|
-
#
|
|
278
|
-
#
|
|
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=
|
|
285
|
-
# - add?(
|
|
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
|
-
#
|
|
289
|
-
#
|
|
290
|
-
# Set[1, 2].add?(
|
|
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=
|
|
297
|
-
# - include?(
|
|
336
|
+
# rdoc-file=set.c
|
|
337
|
+
# - include?(item) -> true or false
|
|
298
338
|
# -->
|
|
299
|
-
# Returns true if the set contains the given object
|
|
300
|
-
#
|
|
301
|
-
#
|
|
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?: (
|
|
359
|
+
def include?: (Hash::_Key) -> bool
|
|
305
360
|
|
|
306
|
-
# <!--
|
|
307
|
-
#
|
|
308
|
-
#
|
|
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=
|
|
315
|
-
# - ^
|
|
385
|
+
# rdoc-file=set.c
|
|
386
|
+
# - set ^ enum -> new_set
|
|
316
387
|
# -->
|
|
317
|
-
# Returns a new set containing elements exclusive between the set
|
|
318
|
-
#
|
|
319
|
-
#
|
|
320
|
-
#
|
|
321
|
-
# Set[1,
|
|
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=
|
|
327
|
-
# - classify
|
|
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
|
-
#
|
|
331
|
-
#
|
|
332
|
-
#
|
|
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
|
|
337
|
-
# # 2001
|
|
338
|
-
# # 2002
|
|
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=
|
|
346
|
-
# - clear
|
|
417
|
+
# rdoc-file=set.c
|
|
418
|
+
# - clear -> self
|
|
347
419
|
# -->
|
|
348
420
|
# Removes all elements and returns self.
|
|
349
|
-
#
|
|
350
|
-
# set
|
|
351
|
-
# 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=
|
|
357
|
-
# - collect!
|
|
429
|
+
# rdoc-file=set.c
|
|
430
|
+
# - collect! { |o| ... } -> self
|
|
431
|
+
# - collect! -> enumerator
|
|
358
432
|
# -->
|
|
359
|
-
# Replaces the elements with ones returned by `collect
|
|
360
|
-
#
|
|
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
|
-
#
|
|
366
|
-
#
|
|
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=
|
|
373
|
-
# - delete(
|
|
445
|
+
# rdoc-file=set.c
|
|
446
|
+
# - delete(obj) -> self
|
|
374
447
|
# -->
|
|
375
|
-
# Deletes the given object from the set and returns self. Use
|
|
376
|
-
#
|
|
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=
|
|
382
|
-
# - delete?(
|
|
454
|
+
# rdoc-file=set.c
|
|
455
|
+
# - delete?(obj) -> self or nil
|
|
383
456
|
# -->
|
|
384
|
-
# Deletes the given object from the set and returns self.
|
|
385
|
-
#
|
|
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=
|
|
391
|
-
# - delete_if
|
|
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
|
-
#
|
|
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=
|
|
401
|
-
# - reject!
|
|
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
|
-
#
|
|
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=
|
|
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=
|
|
419
|
-
# -
|
|
491
|
+
# rdoc-file=set.c
|
|
492
|
+
# - compare_by_identity? -> true or false
|
|
420
493
|
# -->
|
|
421
|
-
# Returns true if the set
|
|
422
|
-
#
|
|
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=
|
|
432
|
-
# - divide
|
|
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
|
-
#
|
|
436
|
-
#
|
|
437
|
-
#
|
|
438
|
-
#
|
|
439
|
-
#
|
|
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 #=>
|
|
443
|
-
# #
|
|
444
|
-
# #
|
|
445
|
-
# #
|
|
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=
|
|
454
|
-
# - each
|
|
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
|
-
#
|
|
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=
|
|
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=
|
|
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
|
-
#
|
|
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=
|
|
482
|
-
# -
|
|
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
|
-
#
|
|
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=
|
|
495
|
-
# - keep_if
|
|
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
|
-
#
|
|
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=
|
|
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
|
-
#
|
|
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=
|
|
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
|
-
#
|
|
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=
|
|
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=
|
|
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=
|
|
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=
|
|
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=
|
|
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
|
-
#
|
|
565
|
-
#
|
|
566
|
-
# set
|
|
567
|
-
# set
|
|
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=
|
|
573
|
-
# - reset
|
|
687
|
+
# rdoc-file=set.c
|
|
688
|
+
# - reset -> self
|
|
574
689
|
# -->
|
|
575
|
-
# Resets the internal state after modification to existing elements
|
|
576
|
-
# and
|
|
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=
|
|
583
|
-
# - select!
|
|
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
|
-
#
|
|
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=
|
|
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
|
-
#
|
|
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=
|
|
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=
|
|
614
|
-
# - to_set(
|
|
743
|
+
# rdoc-file=prelude.rb
|
|
744
|
+
# - to_set(*args, &block)
|
|
615
745
|
# -->
|
|
616
|
-
# Makes a set from the enumerable object with given arguments.
|
|
617
|
-
#
|
|
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]
|