rbs 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -0
- data/CHANGELOG.md +23 -0
- data/README.md +6 -1
- data/core/array.rbs +2866 -1086
- data/core/basic_object.rbs +150 -30
- data/core/binding.rbs +33 -0
- data/core/builtin.rbs +4 -4
- data/core/class.rbs +43 -5
- data/core/comparable.rbs +57 -0
- data/core/complex.rbs +170 -4
- data/core/constants.rbs +51 -0
- data/core/deprecated.rbs +7 -0
- data/core/dir.rbs +305 -20
- data/core/encoding.rbs +472 -77
- data/core/enumerable.rbs +2173 -234
- data/core/enumerator.rbs +448 -182
- data/core/env.rbs +448 -1
- data/core/errno.rbs +1 -10
- data/core/errors.rbs +152 -2
- data/core/exception.rbs +201 -127
- data/core/false_class.rbs +27 -0
- data/core/fiber.rbs +118 -37
- data/core/fiber_error.rbs +8 -9
- data/core/file.rbs +1059 -139
- data/core/file_test.rbs +287 -32
- data/core/float.rbs +776 -300
- data/core/gc.rbs +185 -34
- data/core/global_variables.rbs +5 -1
- data/core/hash.rbs +1582 -649
- data/core/integer.rbs +974 -204
- data/core/io/buffer.rbs +710 -0
- data/core/io/wait.rbs +29 -8
- data/core/io.rbs +2438 -417
- data/core/kernel.rbs +2315 -316
- data/core/marshal.rbs +37 -2
- data/core/match_data.rbs +123 -6
- data/core/math.rbs +126 -6
- data/core/method.rbs +226 -102
- data/core/module.rbs +421 -45
- data/core/nil_class.rbs +64 -0
- data/core/numeric.rbs +620 -142
- data/core/object.rbs +453 -81
- data/core/object_space.rbs +92 -2
- data/core/proc.rbs +482 -285
- data/core/process.rbs +443 -34
- data/core/ractor.rbs +232 -9
- data/core/random.rbs +151 -52
- data/core/range.rbs +885 -160
- data/core/rational.rbs +122 -6
- data/core/rb_config.rbs +14 -4
- data/core/refinement.rbs +44 -0
- data/core/regexp.rbs +156 -14
- data/core/ruby_vm.rbs +42 -3
- data/core/signal.rbs +78 -39
- data/core/string.rbs +2123 -567
- data/core/string_io.rbs +204 -0
- data/core/struct.rbs +283 -28
- data/core/symbol.rbs +304 -30
- data/core/thread.rbs +1288 -688
- data/core/thread_group.rbs +66 -10
- data/core/time.rbs +643 -217
- data/core/trace_point.rbs +100 -12
- data/core/true_class.rbs +24 -0
- data/core/unbound_method.rbs +73 -7
- data/core/warning.rbs +37 -12
- data/docs/CONTRIBUTING.md +40 -34
- data/docs/stdlib.md +3 -102
- data/lib/rbs/annotate/annotations.rb +197 -0
- data/lib/rbs/annotate/formatter.rb +80 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
- data/lib/rbs/annotate/rdoc_source.rb +120 -0
- data/lib/rbs/annotate.rb +6 -0
- data/lib/rbs/cli.rb +45 -1
- data/lib/rbs/definition_builder.rb +5 -1
- data/lib/rbs/location_aux.rb +12 -0
- data/lib/rbs/prototype/rb.rb +12 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/cli.rbs +2 -0
- data/sig/collection/{collections.rbs → sources.rbs} +0 -0
- data/sig/location.rbs +6 -0
- data/sig/method_types.rbs +5 -1
- data/sig/polyfill.rbs +78 -0
- data/stdlib/abbrev/0/abbrev.rbs +6 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +31 -0
- data/stdlib/benchmark/0/benchmark.rbs +74 -3
- data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
- data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
- data/stdlib/cgi/0/core.rbs +59 -0
- data/stdlib/coverage/0/coverage.rbs +164 -2
- data/stdlib/csv/0/csv.rbs +2862 -398
- data/stdlib/date/0/date.rbs +483 -25
- data/stdlib/date/0/date_time.rbs +187 -12
- data/stdlib/dbm/0/dbm.rbs +152 -17
- data/stdlib/digest/0/digest.rbs +146 -0
- data/stdlib/erb/0/erb.rbs +65 -245
- data/stdlib/fiber/0/fiber.rbs +73 -91
- data/stdlib/fileutils/0/fileutils.rbs +301 -1
- data/stdlib/find/0/find.rbs +9 -0
- data/stdlib/forwardable/0/forwardable.rbs +65 -1
- data/stdlib/io-console/0/io-console.rbs +227 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
- data/stdlib/json/0/json.rbs +1146 -144
- data/stdlib/logger/0/formatter.rbs +24 -0
- data/stdlib/logger/0/log_device.rbs +64 -0
- data/stdlib/logger/0/logger.rbs +165 -13
- data/stdlib/logger/0/period.rbs +10 -0
- data/stdlib/logger/0/severity.rbs +26 -0
- data/stdlib/monitor/0/monitor.rbs +163 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
- data/stdlib/net-http/0/net-http.rbs +1492 -683
- data/stdlib/nkf/0/nkf.rbs +372 -0
- data/stdlib/objspace/0/objspace.rbs +149 -90
- data/stdlib/openssl/0/openssl.rbs +8108 -71
- data/stdlib/optparse/0/optparse.rbs +487 -19
- data/stdlib/pathname/0/pathname.rbs +425 -124
- data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
- data/stdlib/prime/0/integer-extension.rbs +20 -2
- data/stdlib/prime/0/prime.rbs +88 -21
- data/stdlib/pstore/0/pstore.rbs +102 -0
- data/stdlib/pty/0/pty.rbs +64 -14
- data/stdlib/resolv/0/resolv.rbs +420 -31
- data/stdlib/rubygems/0/basic_specification.rbs +4 -1
- data/stdlib/rubygems/0/config_file.rbs +33 -1
- data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
- data/stdlib/rubygems/0/installer.rbs +13 -1
- data/stdlib/rubygems/0/path_support.rbs +4 -1
- data/stdlib/rubygems/0/platform.rbs +5 -1
- data/stdlib/rubygems/0/request_set.rbs +44 -2
- data/stdlib/rubygems/0/requirement.rbs +65 -2
- data/stdlib/rubygems/0/rubygems.rbs +407 -0
- data/stdlib/rubygems/0/source_list.rbs +13 -0
- data/stdlib/rubygems/0/specification.rbs +21 -1
- data/stdlib/rubygems/0/stream_ui.rbs +3 -1
- data/stdlib/rubygems/0/uninstaller.rbs +8 -1
- data/stdlib/rubygems/0/version.rbs +60 -157
- data/stdlib/securerandom/0/securerandom.rbs +44 -0
- data/stdlib/set/0/set.rbs +420 -106
- data/stdlib/shellwords/0/shellwords.rbs +55 -77
- data/stdlib/singleton/0/singleton.rbs +20 -0
- data/stdlib/socket/0/addrinfo.rbs +210 -9
- data/stdlib/socket/0/basic_socket.rbs +103 -11
- data/stdlib/socket/0/ip_socket.rbs +31 -9
- data/stdlib/socket/0/socket.rbs +586 -38
- data/stdlib/socket/0/tcp_server.rbs +22 -2
- data/stdlib/socket/0/tcp_socket.rbs +12 -1
- data/stdlib/socket/0/udp_socket.rbs +25 -2
- data/stdlib/socket/0/unix_server.rbs +22 -2
- data/stdlib/socket/0/unix_socket.rbs +45 -5
- data/stdlib/strscan/0/string_scanner.rbs +210 -9
- data/stdlib/tempfile/0/tempfile.rbs +58 -10
- data/stdlib/time/0/time.rbs +208 -116
- data/stdlib/timeout/0/timeout.rbs +10 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
- data/stdlib/tsort/0/cyclic.rbs +1 -0
- data/stdlib/tsort/0/interfaces.rbs +1 -0
- data/stdlib/tsort/0/tsort.rbs +42 -0
- data/stdlib/uri/0/common.rbs +57 -8
- data/stdlib/uri/0/file.rbs +55 -109
- data/stdlib/uri/0/ftp.rbs +6 -3
- data/stdlib/uri/0/generic.rbs +556 -327
- data/stdlib/uri/0/http.rbs +26 -115
- data/stdlib/uri/0/https.rbs +8 -102
- data/stdlib/uri/0/ldap.rbs +143 -137
- data/stdlib/uri/0/ldaps.rbs +8 -102
- data/stdlib/uri/0/mailto.rbs +3 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
- data/stdlib/uri/0/ws.rbs +6 -3
- data/stdlib/uri/0/wss.rbs +5 -3
- data/stdlib/yaml/0/dbm.rbs +151 -87
- data/stdlib/yaml/0/store.rbs +6 -0
- data/stdlib/zlib/0/zlib.rbs +90 -31
- metadata +17 -5
- data/lib/rbs/location.rb +0 -221
data/stdlib/set/0/set.rbs
CHANGED
@@ -1,50 +1,200 @@
|
|
1
|
-
#
|
2
|
-
#
|
1
|
+
# <!-- rdoc-file=lib/set.rb -->
|
2
|
+
# This library provides the Set class, which deals with a collection
|
3
|
+
# of unordered values with no duplicates. It is a hybrid of Array's
|
4
|
+
# intuitive inter-operation facilities and Hash's fast lookup.
|
5
|
+
# The method `to_set` is added to Enumerable for convenience.
|
6
|
+
# Set implements a collection of unordered values with no duplicates.
|
7
|
+
# This is a hybrid of Array's intuitive inter-operation facilities and
|
8
|
+
# Hash's fast lookup.
|
9
|
+
# Set is easy to use with Enumerable objects (implementing `each`).
|
10
|
+
# Most of the initializer methods and binary operators accept generic
|
11
|
+
# Enumerable objects besides sets and arrays. An Enumerable object
|
12
|
+
# can be converted to Set using the `to_set` method.
|
13
|
+
# Set uses Hash as storage, so you must note the following points:
|
14
|
+
# * Equality of elements is determined according to Object#eql? and
|
15
|
+
# Object#hash. Use Set#compare_by_identity to make a set compare
|
16
|
+
# its elements by their identity.
|
17
|
+
# * Set assumes that the identity of each element does not change
|
18
|
+
# while it is stored. Modifying an element of a set will render the
|
19
|
+
# set to an unreliable state.
|
20
|
+
# * When a string is to be stored, a frozen copy of the string is
|
21
|
+
# stored instead unless the original string is already frozen.
|
3
22
|
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
23
|
+
# ## Comparison
|
24
|
+
# The comparison operators `<`, `>`, `<=`, and `>=` are implemented as
|
25
|
+
# shorthand for the {proper_,}{subset?,superset?} methods. The `<=>`
|
26
|
+
# operator reflects this order, or return `nil` for sets that both
|
27
|
+
# have distinct elements (`{x, y}` vs. `{x, z}` for example).
|
28
|
+
# ## Example
|
29
|
+
# require 'set'
|
30
|
+
# s1 = Set[1, 2] #=> #<Set: {1, 2}>
|
31
|
+
# s2 = [1, 2].to_set #=> #<Set: {1, 2}>
|
32
|
+
# s1 == s2 #=> true
|
33
|
+
# s1.add("foo") #=> #<Set: {1, 2, "foo"}>
|
34
|
+
# s1.merge([2, 6]) #=> #<Set: {1, 2, "foo", 6}>
|
35
|
+
# s1.subset?(s2) #=> false
|
36
|
+
# s2.subset?(s1) #=> true
|
8
37
|
#
|
9
|
-
#
|
38
|
+
# ## Contact
|
39
|
+
# * Akinori MUSHA <mailto:knu@iDaemons.org> (current maintainer)
|
10
40
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
41
|
+
# ## What's Here
|
42
|
+
# First, what's elsewhere. Class Set:
|
43
|
+
# * Inherits from [class
|
44
|
+
# Object](https://docs.ruby-lang.org/en/master/Object.html#class-Object-labe
|
45
|
+
# l-What-27s+Here).
|
46
|
+
# * Includes [module
|
47
|
+
# which provides dozens of additional
|
48
|
+
# g/en/master/Enumerable.html#module-Enumerable-label-What-27s+Here),
|
49
|
+
# which provides dozens of additional methods.
|
19
50
|
#
|
51
|
+
# In particular, class Set does not have many methods of its own
|
52
|
+
# for fetching or for iterating.
|
53
|
+
# Instead, it relies on those in Enumerable.
|
54
|
+
# Here, class Set provides methods that are useful for:
|
55
|
+
# * [Creating a Set](#class-Set-label-Methods+for+Creating+a+Set)
|
56
|
+
# * [Set Operations](#class-Set-label-Methods+for+Set+Operations)
|
57
|
+
# * [Comparing](#class-Set-label-Methods+for+Comparing)
|
58
|
+
# * [Querying](#class-Set-label-Methods+for+Querying)
|
59
|
+
# * [Assigning](#class-Set-label-Methods+for+Assigning)
|
60
|
+
# * [Deleting](#class-Set-label-Methods+for+Deleting)
|
61
|
+
# * [Converting](#class-Set-label-Methods+for+Converting)
|
62
|
+
# * [Iterating](#class-Set-label-Methods+for+Iterating)
|
63
|
+
# * [And more....](#class-Set-label-Other+Methods)
|
20
64
|
#
|
21
|
-
#
|
65
|
+
# ### Methods for Creating a Set
|
66
|
+
# * ::[] -
|
67
|
+
# Returns a new set containing the given objects.
|
68
|
+
# * ::new -
|
69
|
+
# Returns a new set containing either the given objects
|
70
|
+
# (if no block given) or the return values from the called block
|
71
|
+
# (if a block given).
|
22
72
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
73
|
+
# ### Methods for Set Operations
|
74
|
+
# * [|](#method-i-7C) (aliased as #union and #+) -
|
75
|
+
# Returns a new set containing all elements from `self`
|
76
|
+
# and all elements from a given enumerable (no duplicates).
|
77
|
+
# * [&](#method-i-26) (aliased as #intersection) -
|
78
|
+
# Returns a new set containing all elements common to `self`
|
79
|
+
# and a given enumerable.
|
80
|
+
# * [-](#method-i-2D) (aliased as #difference) -
|
81
|
+
# Returns a copy of `self` with all elements
|
82
|
+
# in a given enumerable removed.
|
83
|
+
# * [\^](#method-i-5E) -
|
84
|
+
# Returns a new set containing all elements from `self`
|
85
|
+
# and a given enumerable except those common to both.
|
27
86
|
#
|
28
|
-
#
|
87
|
+
# ### Methods for Comparing
|
88
|
+
# * [<=>](#method-i-3C-3D-3E) -
|
89
|
+
# Returns -1, 0, or 1 as `self` is less than, equal to,
|
90
|
+
# or greater than a given object.
|
91
|
+
# * [==](#method-i-3D-3D) -
|
92
|
+
# Returns whether `self` and a given enumerable are equal,
|
93
|
+
# as determined by Object#eql?.
|
94
|
+
# * #compare_by_identity? -
|
95
|
+
# Returns whether the set considers only identity
|
96
|
+
# when comparing elements.
|
29
97
|
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
98
|
+
# ### Methods for Querying
|
99
|
+
# * #length (aliased as #size) -
|
100
|
+
# Returns the count of elements.
|
101
|
+
# * #empty? -
|
102
|
+
# Returns whether the set has no elements.
|
103
|
+
# * #include? (aliased as #member? and #===) -
|
104
|
+
# Returns whether a given object is an element in the set.
|
105
|
+
# * #subset? (aliased as [<=](#method-i-3C-3D)) -
|
106
|
+
# Returns whether a given object is a subset of the set.
|
107
|
+
# * #proper_subset? (aliased as [<](#method-i-3C)) -
|
108
|
+
# Returns whether a given enumerable is a proper subset of the set.
|
109
|
+
# * #superset? (aliased as [<=](#method-i-3E-3D)]) -
|
110
|
+
# Returns whether a given enumerable is a superset of the set.
|
111
|
+
# * #proper_superset? (aliased as [>](#method-i-3E)) -
|
112
|
+
# Returns whether a given enumerable is a proper superset of the set.
|
113
|
+
# * #disjoint? -
|
114
|
+
# Returns `true` if the set and a given enumerable
|
115
|
+
# have no common elements, `false` otherwise.
|
116
|
+
# * #intersect? -
|
117
|
+
# Returns `true` if the set and a given enumerable -
|
118
|
+
# have any common elements, `false` otherwise.
|
119
|
+
# * #compare_by_identity? -
|
120
|
+
# Returns whether the set considers only identity
|
121
|
+
# when comparing elements.
|
38
122
|
#
|
39
|
-
#
|
123
|
+
# ### Methods for Assigning
|
124
|
+
# * #add (aliased as #<<) -
|
125
|
+
# Adds a given object to the set; returns `self`.
|
126
|
+
# * #add? -
|
127
|
+
# If the given object is not an element in the set,
|
128
|
+
# adds it and returns `self`; otherwise, returns `nil`.
|
129
|
+
# * #merge -
|
130
|
+
# Adds each given object to the set; returns `self`.
|
131
|
+
# * #replace -
|
132
|
+
# Replaces the contents of the set with the contents
|
133
|
+
# of a given enumerable.
|
134
|
+
#
|
135
|
+
# ### Methods for Deleting
|
136
|
+
# * #clear -
|
137
|
+
# Removes all elements in the set; returns `self`.
|
138
|
+
# * #delete -
|
139
|
+
# Removes a given object from the set; returns `self`.
|
140
|
+
# * #delete? -
|
141
|
+
# If the given object is an element in the set,
|
142
|
+
# removes it and returns `self`; otherwise, returns `nil`.
|
143
|
+
# * #subtract -
|
144
|
+
# Removes each given object from the set; returns `self`.
|
145
|
+
# * #delete_if - Removes elements specified by a given block.
|
146
|
+
# * #select! (aliased as #filter!) -
|
147
|
+
# Removes elements not specified by a given block.
|
148
|
+
# * #keep_if -
|
149
|
+
# Removes elements not specified by a given block.
|
150
|
+
# * #reject!
|
151
|
+
# Removes elements specified by a given block.
|
152
|
+
#
|
153
|
+
# ### Methods for Converting
|
154
|
+
# * #classify -
|
155
|
+
# Returns a hash that classifies the elements,
|
156
|
+
# as determined by the given block.
|
157
|
+
# * #collect! (aliased as #map!) -
|
158
|
+
# Replaces each element with a block return-value.
|
159
|
+
# * #divide -
|
160
|
+
# Returns a hash that classifies the elements,
|
161
|
+
# as determined by the given block;
|
162
|
+
# differs from #classify in that the block may accept
|
163
|
+
# either one or two arguments.
|
164
|
+
# * #flatten -
|
165
|
+
# Returns a new set that is a recursive flattening of `self`.
|
166
|
+
# #flatten! -
|
167
|
+
# Replaces each nested set in `self` with the elements from that set.
|
168
|
+
# * #inspect (aliased as #to_s) -
|
169
|
+
# Returns a string displaying the elements.
|
170
|
+
# * #join -
|
171
|
+
# Returns a string containing all elements, converted to strings
|
172
|
+
# as needed, and joined by the given record separator.
|
173
|
+
# * #to_a -
|
174
|
+
# Returns an array containing all set elements.
|
175
|
+
# * #to_set -
|
176
|
+
# Returns `self` if given no arguments and no block;
|
177
|
+
# with a block given, returns a new set consisting of block
|
178
|
+
# return values.
|
40
179
|
#
|
41
|
-
#
|
180
|
+
# ### Methods for Iterating
|
181
|
+
# * #each -
|
182
|
+
# Calls the block with each successive element; returns `self`.
|
183
|
+
#
|
184
|
+
# ### Other Methods
|
185
|
+
# * #reset -
|
186
|
+
# Resets the internal state; useful if an object
|
187
|
+
# has been modified while an element in the set.
|
42
188
|
#
|
43
189
|
class Set[A]
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
190
|
+
# <!--
|
191
|
+
# rdoc-file=lib/set.rb
|
192
|
+
# - new(enum = nil) { |o| ... }
|
193
|
+
# -->
|
194
|
+
# Creates a new set containing the elements of the given enumerable
|
195
|
+
# object.
|
196
|
+
# If a block is given, the elements of enum are preprocessed by the
|
197
|
+
# given block.
|
48
198
|
# Set.new([1, 2]) #=> #<Set: {1, 2}>
|
49
199
|
# Set.new([1, 2, 1]) #=> #<Set: {1, 2}>
|
50
200
|
# Set.new([1, 'c', :s]) #=> #<Set: {1, "c", :s}>
|
@@ -55,90 +205,147 @@ class Set[A]
|
|
55
205
|
| [X] (_Each[X]) { (X) -> A } -> untyped
|
56
206
|
| (?nil) -> untyped
|
57
207
|
|
208
|
+
# <!--
|
209
|
+
# rdoc-file=lib/set.rb
|
210
|
+
# - [](*ary)
|
211
|
+
# -->
|
58
212
|
# Creates a new set containing the given objects.
|
59
|
-
#
|
60
213
|
# Set[1, 2] # => #<Set: {1, 2}>
|
61
214
|
# Set[1, 2, 1] # => #<Set: {1, 2}>
|
62
215
|
# Set[1, 'c', :s] # => #<Set: {1, "c", :s}>
|
63
216
|
#
|
64
217
|
def self.[]: [X] (*X) -> Set[X]
|
65
218
|
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
219
|
+
# <!--
|
220
|
+
# rdoc-file=lib/set.rb
|
221
|
+
# - &(enum)
|
222
|
+
# -->
|
223
|
+
# Returns a new set containing elements common to the set and the
|
224
|
+
# given enumerable object.
|
69
225
|
# Set[1, 3, 5] & Set[3, 2, 1] #=> #<Set: {3, 1}>
|
70
226
|
# Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
|
71
227
|
#
|
72
228
|
def &: (_Each[A]) -> self
|
73
229
|
|
230
|
+
# <!--
|
231
|
+
# rdoc-file=lib/set.rb
|
232
|
+
# - intersection(enum)
|
233
|
+
# -->
|
234
|
+
#
|
74
235
|
alias intersection &
|
75
236
|
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
237
|
+
# <!--
|
238
|
+
# rdoc-file=lib/set.rb
|
239
|
+
# - |(enum)
|
240
|
+
# -->
|
241
|
+
# Returns a new set built by merging the set and the elements of the
|
242
|
+
# given enumerable object.
|
79
243
|
# Set[1, 2, 3] | Set[2, 4, 5] #=> #<Set: {1, 2, 3, 4, 5}>
|
80
244
|
# Set[1, 5, 'z'] | (1..6) #=> #<Set: {1, 5, "z", 2, 3, 4, 6}>
|
81
245
|
#
|
82
246
|
def |: (_Each[A]) -> self
|
83
247
|
|
248
|
+
# <!--
|
249
|
+
# rdoc-file=lib/set.rb
|
250
|
+
# - union(enum)
|
251
|
+
# -->
|
252
|
+
#
|
84
253
|
alias union |
|
85
254
|
|
255
|
+
# <!--
|
256
|
+
# rdoc-file=lib/set.rb
|
257
|
+
# - +(enum)
|
258
|
+
# -->
|
259
|
+
#
|
86
260
|
alias + |
|
87
261
|
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
262
|
+
# <!--
|
263
|
+
# rdoc-file=lib/set.rb
|
264
|
+
# - -(enum)
|
265
|
+
# -->
|
266
|
+
# Returns a new set built by duplicating the set, removing every
|
267
|
+
# element that appears in the given enumerable object.
|
91
268
|
# Set[1, 3, 5] - Set[1, 5] #=> #<Set: {3}>
|
92
269
|
# Set['a', 'b', 'z'] - ['a', 'c'] #=> #<Set: {"b", "z"}>
|
93
270
|
#
|
94
271
|
def -: (_Each[A]) -> self
|
95
272
|
|
273
|
+
# <!--
|
274
|
+
# rdoc-file=lib/set.rb
|
275
|
+
# - difference(enum)
|
276
|
+
# -->
|
277
|
+
#
|
96
278
|
alias difference -
|
97
279
|
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
280
|
+
# <!--
|
281
|
+
# rdoc-file=lib/set.rb
|
282
|
+
# - add(o)
|
283
|
+
# -->
|
284
|
+
# Adds the given object to the set and returns self. Use `merge` to
|
285
|
+
# add many elements at once.
|
101
286
|
# Set[1, 2].add(3) #=> #<Set: {1, 2, 3}>
|
102
287
|
# Set[1, 2].add([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
|
103
288
|
# Set[1, 2].add(2) #=> #<Set: {1, 2}>
|
104
289
|
#
|
105
290
|
def add: (A) -> self
|
106
291
|
|
292
|
+
# <!--
|
293
|
+
# rdoc-file=lib/set.rb
|
294
|
+
# - <<(o)
|
295
|
+
# -->
|
296
|
+
#
|
107
297
|
alias << add
|
108
298
|
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
299
|
+
# <!--
|
300
|
+
# rdoc-file=lib/set.rb
|
301
|
+
# - add?(o)
|
302
|
+
# -->
|
303
|
+
# Adds the given object to the set and returns self. If the
|
304
|
+
# object is already in the set, returns nil.
|
112
305
|
# Set[1, 2].add?(3) #=> #<Set: {1, 2, 3}>
|
113
306
|
# Set[1, 2].add?([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
|
114
307
|
# Set[1, 2].add?(2) #=> nil
|
115
308
|
#
|
116
309
|
def add?: (A) -> self?
|
117
310
|
|
311
|
+
# <!--
|
312
|
+
# rdoc-file=lib/set.rb
|
313
|
+
# - include?(o)
|
314
|
+
# -->
|
118
315
|
# Returns true if the set contains the given object.
|
119
|
-
#
|
120
|
-
#
|
121
|
-
# do other Enumerables.
|
122
|
-
#
|
316
|
+
# Note that `include?` and `member?` do not test member
|
317
|
+
# equality using `==` as do other Enumerables.
|
123
318
|
# See also Enumerable#include?
|
124
319
|
#
|
125
320
|
def include?: (A) -> bool
|
126
321
|
|
322
|
+
# <!--
|
323
|
+
# rdoc-file=lib/set.rb
|
324
|
+
# - member?(o)
|
325
|
+
# -->
|
326
|
+
#
|
127
327
|
alias member? include?
|
128
328
|
|
129
|
-
#
|
130
|
-
#
|
131
|
-
# enum)
|
132
|
-
#
|
329
|
+
# <!--
|
330
|
+
# rdoc-file=lib/set.rb
|
331
|
+
# - ^(enum)
|
332
|
+
# -->
|
333
|
+
# Returns a new set containing elements exclusive between the set
|
334
|
+
# and the given enumerable object. `(set ^ enum)` is equivalent to
|
335
|
+
# `((set | enum) - (set & enum))`.
|
133
336
|
# Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
|
134
337
|
# Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
|
135
338
|
#
|
136
339
|
def ^: (_Each[A]) -> self
|
137
340
|
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
341
|
+
# <!--
|
342
|
+
# rdoc-file=lib/set.rb
|
343
|
+
# - classify() { |o| ... }
|
344
|
+
# -->
|
345
|
+
# Classifies the set by the return value of the given block and
|
346
|
+
# returns a hash of {value => set of elements} pairs. The block is
|
347
|
+
# called once for each element of the set, passing the element as
|
348
|
+
# parameter.
|
142
349
|
# require 'set'
|
143
350
|
# files = Set.new(Dir.glob("*.rb"))
|
144
351
|
# hash = files.classify { |f| File.mtime(f).year }
|
@@ -150,56 +357,92 @@ class Set[A]
|
|
150
357
|
#
|
151
358
|
def classify: [X] () { (A) -> X } -> Hash[X, self]
|
152
359
|
|
360
|
+
# <!--
|
361
|
+
# rdoc-file=lib/set.rb
|
362
|
+
# - clear()
|
363
|
+
# -->
|
153
364
|
# Removes all elements and returns self.
|
154
|
-
#
|
155
365
|
# set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
|
156
366
|
# set.clear #=> #<Set: {}>
|
157
367
|
# set #=> #<Set: {}>
|
158
368
|
#
|
159
369
|
def clear: () -> self
|
160
370
|
|
161
|
-
#
|
162
|
-
#
|
371
|
+
# <!--
|
372
|
+
# rdoc-file=lib/set.rb
|
373
|
+
# - collect!() { |o| ... }
|
374
|
+
# -->
|
375
|
+
# Replaces the elements with ones returned by `collect()`.
|
376
|
+
# Returns an enumerator if no block is given.
|
163
377
|
#
|
164
378
|
def collect!: () { (A) -> A } -> self
|
165
379
|
|
380
|
+
# <!--
|
381
|
+
# rdoc-file=lib/set.rb
|
382
|
+
# - map!()
|
383
|
+
# -->
|
384
|
+
#
|
166
385
|
alias map! collect!
|
167
386
|
|
168
|
-
#
|
169
|
-
#
|
387
|
+
# <!--
|
388
|
+
# rdoc-file=lib/set.rb
|
389
|
+
# - delete(o)
|
390
|
+
# -->
|
391
|
+
# Deletes the given object from the set and returns self. Use
|
392
|
+
# `subtract` to delete many items at once.
|
170
393
|
#
|
171
394
|
def delete: (A) -> self
|
172
395
|
|
173
|
-
#
|
174
|
-
#
|
396
|
+
# <!--
|
397
|
+
# rdoc-file=lib/set.rb
|
398
|
+
# - delete?(o)
|
399
|
+
# -->
|
400
|
+
# Deletes the given object from the set and returns self. If the
|
401
|
+
# object is not in the set, returns nil.
|
175
402
|
#
|
176
403
|
def delete?: (A) -> self?
|
177
404
|
|
178
|
-
#
|
179
|
-
#
|
405
|
+
# <!--
|
406
|
+
# rdoc-file=lib/set.rb
|
407
|
+
# - delete_if() { |o| ... }
|
408
|
+
# -->
|
409
|
+
# Deletes every element of the set for which block evaluates to
|
410
|
+
# true, and returns self. Returns an enumerator if no block is
|
411
|
+
# given.
|
180
412
|
#
|
181
413
|
def delete_if: () { (A) -> untyped } -> self
|
182
414
|
|
183
|
-
#
|
184
|
-
#
|
415
|
+
# <!--
|
416
|
+
# rdoc-file=lib/set.rb
|
417
|
+
# - reject!(&block)
|
418
|
+
# -->
|
419
|
+
# Equivalent to Set#delete_if, but returns nil if no changes were
|
420
|
+
# made. Returns an enumerator if no block is given.
|
185
421
|
#
|
186
422
|
def reject!: () { (A) -> untyped } -> self
|
187
423
|
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
424
|
+
# <!--
|
425
|
+
# rdoc-file=lib/set.rb
|
426
|
+
# - disjoint?(set)
|
427
|
+
# -->
|
428
|
+
# Returns true if the set and the given enumerable have
|
429
|
+
# no element in common. This method is the opposite of `intersect?`.
|
191
430
|
# Set[1, 2, 3].disjoint? Set[3, 4] #=> false
|
192
431
|
# Set[1, 2, 3].disjoint? Set[4, 5] #=> true
|
432
|
+
# Set[1, 2, 3].disjoint? [3, 4] #=> false
|
433
|
+
# Set[1, 2, 3].disjoint? 4..5 #=> true
|
193
434
|
#
|
194
435
|
def disjoint?: (self) -> bool
|
195
436
|
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
437
|
+
# <!--
|
438
|
+
# rdoc-file=lib/set.rb
|
439
|
+
# - divide(&func)
|
440
|
+
# -->
|
441
|
+
# Divides the set into a set of subsets according to the commonality
|
442
|
+
# defined by the given block.
|
443
|
+
# If the arity of the block is 2, elements o1 and o2 are in common
|
444
|
+
# if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are
|
445
|
+
# in common if block.call(o1) == block.call(o2).
|
203
446
|
# require 'set'
|
204
447
|
# numbers = Set[1, 3, 4, 6, 9, 10, 11]
|
205
448
|
# set = numbers.divide { |i,j| (i - j).abs == 1 }
|
@@ -213,85 +456,151 @@ class Set[A]
|
|
213
456
|
def divide: () { (A, A) -> untyped } -> Set[self]
|
214
457
|
| () { (A) -> untyped } -> Set[self]
|
215
458
|
|
216
|
-
#
|
217
|
-
#
|
459
|
+
# <!--
|
460
|
+
# rdoc-file=lib/set.rb
|
461
|
+
# - each(&block)
|
462
|
+
# -->
|
463
|
+
# Calls the given block once for each element in the set, passing
|
464
|
+
# the element as parameter. Returns an enumerator if no block is
|
465
|
+
# given.
|
218
466
|
#
|
219
467
|
def each: () { (A) -> void } -> self
|
220
468
|
|
469
|
+
# <!--
|
470
|
+
# rdoc-file=lib/set.rb
|
471
|
+
# - empty?()
|
472
|
+
# -->
|
221
473
|
# Returns true if the set contains no elements.
|
222
474
|
#
|
223
475
|
def empty?: () -> bool
|
224
476
|
|
225
|
-
#
|
226
|
-
#
|
477
|
+
# <!--
|
478
|
+
# rdoc-file=lib/set.rb
|
479
|
+
# - flatten()
|
480
|
+
# -->
|
481
|
+
# Returns a new set that is a copy of the set, flattening each
|
482
|
+
# containing set recursively.
|
227
483
|
#
|
228
484
|
def flatten: () -> Set[untyped]
|
229
485
|
|
230
|
-
#
|
231
|
-
#
|
486
|
+
# <!--
|
487
|
+
# rdoc-file=lib/set.rb
|
488
|
+
# - intersect?(set)
|
489
|
+
# -->
|
490
|
+
# Returns true if the set and the given enumerable have at least one
|
491
|
+
# element in common.
|
232
492
|
# Set[1, 2, 3].intersect? Set[4, 5] #=> false
|
233
493
|
# Set[1, 2, 3].intersect? Set[3, 4] #=> true
|
494
|
+
# Set[1, 2, 3].intersect? 4..5 #=> false
|
495
|
+
# Set[1, 2, 3].intersect? [3, 4] #=> true
|
234
496
|
#
|
235
497
|
def intersect?: (self) -> bool
|
236
498
|
|
237
|
-
#
|
238
|
-
#
|
499
|
+
# <!--
|
500
|
+
# rdoc-file=lib/set.rb
|
501
|
+
# - keep_if() { |o| ... }
|
502
|
+
# -->
|
503
|
+
# Deletes every element of the set for which block evaluates to
|
504
|
+
# false, and returns self. Returns an enumerator if no block is
|
505
|
+
# given.
|
239
506
|
#
|
240
507
|
def keep_if: () { (A) -> untyped } -> self
|
241
508
|
|
509
|
+
# <!--
|
510
|
+
# rdoc-file=lib/set.rb
|
511
|
+
# - size()
|
512
|
+
# -->
|
242
513
|
# Returns the number of elements.
|
243
514
|
#
|
244
515
|
def size: () -> Integer
|
245
516
|
|
517
|
+
# <!--
|
518
|
+
# rdoc-file=lib/set.rb
|
519
|
+
# - length()
|
520
|
+
# -->
|
521
|
+
#
|
246
522
|
alias length size
|
247
523
|
|
248
|
-
#
|
249
|
-
#
|
524
|
+
# <!--
|
525
|
+
# rdoc-file=lib/set.rb
|
526
|
+
# - merge(enum)
|
527
|
+
# -->
|
528
|
+
# Merges the elements of the given enumerable object to the set and
|
529
|
+
# returns self.
|
250
530
|
#
|
251
531
|
def merge: (_Each[A]) -> self
|
252
532
|
|
533
|
+
# <!--
|
534
|
+
# rdoc-file=lib/set.rb
|
535
|
+
# - subset?(set)
|
536
|
+
# -->
|
253
537
|
# Returns true if the set is a subset of the given set.
|
254
538
|
#
|
255
539
|
def subset?: (self) -> bool
|
256
540
|
|
257
541
|
def proper_subst?: (self) -> bool
|
258
542
|
|
543
|
+
# <!--
|
544
|
+
# rdoc-file=lib/set.rb
|
545
|
+
# - superset?(set)
|
546
|
+
# -->
|
259
547
|
# Returns true if the set is a superset of the given set.
|
260
548
|
#
|
261
549
|
def superset?: (self) -> bool
|
262
550
|
|
551
|
+
# <!--
|
552
|
+
# rdoc-file=lib/set.rb
|
553
|
+
# - proper_superset?(set)
|
554
|
+
# -->
|
263
555
|
# Returns true if the set is a proper superset of the given set.
|
264
556
|
#
|
265
557
|
def proper_superset?: (self) -> bool
|
266
558
|
|
267
|
-
#
|
268
|
-
#
|
269
|
-
#
|
559
|
+
# <!--
|
560
|
+
# rdoc-file=lib/set.rb
|
561
|
+
# - replace(enum)
|
562
|
+
# -->
|
563
|
+
# Replaces the contents of the set with the contents of the given
|
564
|
+
# enumerable object and returns self.
|
270
565
|
# set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
|
271
566
|
# set.replace([1, 2]) #=> #<Set: {1, 2}>
|
272
567
|
# set #=> #<Set: {1, 2}>
|
273
568
|
#
|
274
569
|
def replace: (_Each[A]) -> self
|
275
570
|
|
276
|
-
#
|
277
|
-
#
|
278
|
-
#
|
571
|
+
# <!--
|
572
|
+
# rdoc-file=lib/set.rb
|
573
|
+
# - reset()
|
574
|
+
# -->
|
575
|
+
# Resets the internal state after modification to existing elements
|
576
|
+
# and returns self.
|
279
577
|
# Elements will be reindexed and deduplicated.
|
280
578
|
#
|
281
579
|
def reset: () -> self
|
282
580
|
|
283
|
-
#
|
284
|
-
#
|
581
|
+
# <!--
|
582
|
+
# rdoc-file=lib/set.rb
|
583
|
+
# - select!(&block)
|
584
|
+
# -->
|
585
|
+
# Equivalent to Set#keep_if, but returns nil if no changes were
|
586
|
+
# made. Returns an enumerator if no block is given.
|
285
587
|
#
|
286
588
|
def select!: () { (A) -> untyped } -> self?
|
287
589
|
|
288
|
-
#
|
289
|
-
#
|
590
|
+
# <!--
|
591
|
+
# rdoc-file=lib/set.rb
|
592
|
+
# - subtract(enum)
|
593
|
+
# -->
|
594
|
+
# Deletes every element that appears in the given enumerable object
|
595
|
+
# and returns self.
|
290
596
|
#
|
291
597
|
def subtract: (_Each[A]) -> self
|
292
598
|
|
293
|
-
#
|
294
|
-
#
|
599
|
+
# <!--
|
600
|
+
# rdoc-file=lib/set.rb
|
601
|
+
# - to_a()
|
602
|
+
# -->
|
603
|
+
# Converts the set to an array. The order of elements is uncertain.
|
295
604
|
# Set[1, 2].to_a #=> [1, 2]
|
296
605
|
# Set[1, 'c', :s].to_a #=> [1, "c", :s]
|
297
606
|
#
|
@@ -300,7 +609,12 @@ class Set[A]
|
|
300
609
|
include Enumerable[A]
|
301
610
|
end
|
302
611
|
|
612
|
+
%a{annotate:rdoc:skip}
|
303
613
|
module Enumerable[unchecked out Elem]
|
614
|
+
# <!--
|
615
|
+
# rdoc-file=lib/set.rb
|
616
|
+
# - to_set(klass = Set, *args, &block)
|
617
|
+
# -->
|
304
618
|
# Makes a set from the enumerable object with given arguments.
|
305
619
|
# Needs to `require "set"` to use this method.
|
306
620
|
#
|