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