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