rbs 2.0.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +34 -0
- data/.github/workflows/ruby.yml +5 -0
- data/CHANGELOG.md +82 -0
- data/README.md +6 -1
- data/Rakefile +56 -21
- 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 +1214 -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 +1060 -142
- 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 +2319 -318
- 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/docs/syntax.md +54 -11
- data/ext/rbs_extension/extconf.rb +1 -0
- data/ext/rbs_extension/lexer.h +5 -0
- data/ext/rbs_extension/lexstate.c +6 -0
- data/ext/rbs_extension/parser.c +85 -10
- data/ext/rbs_extension/ruby_objs.c +4 -2
- data/ext/rbs_extension/ruby_objs.h +2 -2
- data/goodcheck.yml +0 -11
- 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/ast/members.rb +21 -13
- data/lib/rbs/buffer.rb +17 -11
- data/lib/rbs/cli.rb +48 -1
- data/lib/rbs/definition_builder/method_builder.rb +28 -16
- data/lib/rbs/definition_builder.rb +6 -2
- data/lib/rbs/environment.rb +8 -4
- data/lib/rbs/location_aux.rb +12 -0
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/prototype/rb.rb +12 -0
- data/lib/rbs/type_alias_regularity.rb +6 -4
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +1 -1
- data/lib/rbs/validator.rb +6 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +54 -4
- data/lib/rbs.rb +0 -2
- data/schema/typeParam.json +3 -3
- 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/buffer.rbs +6 -2
- data/sig/cli.rbs +2 -0
- data/sig/collection/{collections.rbs → sources.rbs} +0 -0
- data/sig/location.rbs +6 -0
- data/sig/members.rbs +24 -18
- data/sig/method_builder.rbs +5 -4
- data/sig/method_types.rbs +5 -1
- data/sig/polyfill.rbs +78 -0
- data/sig/validator.rbs +3 -1
- data/sig/writer.rbs +79 -2
- 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 +649 -21
- 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 +1147 -145
- 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/manifest.yaml +1 -0
- data/stdlib/net-http/0/net-http.rbs +1513 -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 +423 -109
- 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 +558 -329
- data/stdlib/uri/0/http.rbs +60 -114
- 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 +18 -6
- data/lib/rbs/location.rb +0 -221
- data/sig/char_scanner.rbs +0 -9
data/stdlib/set/0/set.rbs
CHANGED
|
@@ -1,50 +1,202 @@
|
|
|
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.
|
|
40
134
|
#
|
|
41
|
-
#
|
|
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.
|
|
42
152
|
#
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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.
|
|
179
|
+
#
|
|
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.
|
|
188
|
+
#
|
|
189
|
+
class Set[unchecked out A]
|
|
190
|
+
include Enumerable[A]
|
|
191
|
+
|
|
192
|
+
# <!--
|
|
193
|
+
# rdoc-file=lib/set.rb
|
|
194
|
+
# - new(enum = nil) { |o| ... }
|
|
195
|
+
# -->
|
|
196
|
+
# Creates a new set containing the elements of the given enumerable
|
|
197
|
+
# object.
|
|
198
|
+
# If a block is given, the elements of enum are preprocessed by the
|
|
199
|
+
# given block.
|
|
48
200
|
# Set.new([1, 2]) #=> #<Set: {1, 2}>
|
|
49
201
|
# Set.new([1, 2, 1]) #=> #<Set: {1, 2}>
|
|
50
202
|
# Set.new([1, 'c', :s]) #=> #<Set: {1, "c", :s}>
|
|
@@ -55,90 +207,147 @@ class Set[A]
|
|
|
55
207
|
| [X] (_Each[X]) { (X) -> A } -> untyped
|
|
56
208
|
| (?nil) -> untyped
|
|
57
209
|
|
|
210
|
+
# <!--
|
|
211
|
+
# rdoc-file=lib/set.rb
|
|
212
|
+
# - [](*ary)
|
|
213
|
+
# -->
|
|
58
214
|
# Creates a new set containing the given objects.
|
|
59
|
-
#
|
|
60
215
|
# Set[1, 2] # => #<Set: {1, 2}>
|
|
61
216
|
# Set[1, 2, 1] # => #<Set: {1, 2}>
|
|
62
217
|
# Set[1, 'c', :s] # => #<Set: {1, "c", :s}>
|
|
63
218
|
#
|
|
64
219
|
def self.[]: [X] (*X) -> Set[X]
|
|
65
220
|
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
221
|
+
# <!--
|
|
222
|
+
# rdoc-file=lib/set.rb
|
|
223
|
+
# - &(enum)
|
|
224
|
+
# -->
|
|
225
|
+
# Returns a new set containing elements common to the set and the
|
|
226
|
+
# given enumerable object.
|
|
69
227
|
# Set[1, 3, 5] & Set[3, 2, 1] #=> #<Set: {3, 1}>
|
|
70
228
|
# Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
|
|
71
229
|
#
|
|
72
230
|
def &: (_Each[A]) -> self
|
|
73
231
|
|
|
232
|
+
# <!--
|
|
233
|
+
# rdoc-file=lib/set.rb
|
|
234
|
+
# - intersection(enum)
|
|
235
|
+
# -->
|
|
236
|
+
#
|
|
74
237
|
alias intersection &
|
|
75
238
|
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
#
|
|
239
|
+
# <!--
|
|
240
|
+
# rdoc-file=lib/set.rb
|
|
241
|
+
# - |(enum)
|
|
242
|
+
# -->
|
|
243
|
+
# Returns a new set built by merging the set and the elements of the
|
|
244
|
+
# given enumerable object.
|
|
79
245
|
# Set[1, 2, 3] | Set[2, 4, 5] #=> #<Set: {1, 2, 3, 4, 5}>
|
|
80
246
|
# Set[1, 5, 'z'] | (1..6) #=> #<Set: {1, 5, "z", 2, 3, 4, 6}>
|
|
81
247
|
#
|
|
82
248
|
def |: (_Each[A]) -> self
|
|
83
249
|
|
|
250
|
+
# <!--
|
|
251
|
+
# rdoc-file=lib/set.rb
|
|
252
|
+
# - union(enum)
|
|
253
|
+
# -->
|
|
254
|
+
#
|
|
84
255
|
alias union |
|
|
85
256
|
|
|
257
|
+
# <!--
|
|
258
|
+
# rdoc-file=lib/set.rb
|
|
259
|
+
# - +(enum)
|
|
260
|
+
# -->
|
|
261
|
+
#
|
|
86
262
|
alias + |
|
|
87
263
|
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
#
|
|
264
|
+
# <!--
|
|
265
|
+
# rdoc-file=lib/set.rb
|
|
266
|
+
# - -(enum)
|
|
267
|
+
# -->
|
|
268
|
+
# Returns a new set built by duplicating the set, removing every
|
|
269
|
+
# element that appears in the given enumerable object.
|
|
91
270
|
# Set[1, 3, 5] - Set[1, 5] #=> #<Set: {3}>
|
|
92
271
|
# Set['a', 'b', 'z'] - ['a', 'c'] #=> #<Set: {"b", "z"}>
|
|
93
272
|
#
|
|
94
273
|
def -: (_Each[A]) -> self
|
|
95
274
|
|
|
275
|
+
# <!--
|
|
276
|
+
# rdoc-file=lib/set.rb
|
|
277
|
+
# - difference(enum)
|
|
278
|
+
# -->
|
|
279
|
+
#
|
|
96
280
|
alias difference -
|
|
97
281
|
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
#
|
|
282
|
+
# <!--
|
|
283
|
+
# rdoc-file=lib/set.rb
|
|
284
|
+
# - add(o)
|
|
285
|
+
# -->
|
|
286
|
+
# Adds the given object to the set and returns self. Use `merge` to
|
|
287
|
+
# add many elements at once.
|
|
101
288
|
# Set[1, 2].add(3) #=> #<Set: {1, 2, 3}>
|
|
102
289
|
# Set[1, 2].add([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
|
|
103
290
|
# Set[1, 2].add(2) #=> #<Set: {1, 2}>
|
|
104
291
|
#
|
|
105
292
|
def add: (A) -> self
|
|
106
293
|
|
|
294
|
+
# <!--
|
|
295
|
+
# rdoc-file=lib/set.rb
|
|
296
|
+
# - <<(o)
|
|
297
|
+
# -->
|
|
298
|
+
#
|
|
107
299
|
alias << add
|
|
108
300
|
|
|
109
|
-
#
|
|
110
|
-
#
|
|
111
|
-
#
|
|
301
|
+
# <!--
|
|
302
|
+
# rdoc-file=lib/set.rb
|
|
303
|
+
# - add?(o)
|
|
304
|
+
# -->
|
|
305
|
+
# Adds the given object to the set and returns self. If the
|
|
306
|
+
# object is already in the set, returns nil.
|
|
112
307
|
# Set[1, 2].add?(3) #=> #<Set: {1, 2, 3}>
|
|
113
308
|
# Set[1, 2].add?([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
|
|
114
309
|
# Set[1, 2].add?(2) #=> nil
|
|
115
310
|
#
|
|
116
311
|
def add?: (A) -> self?
|
|
117
312
|
|
|
313
|
+
# <!--
|
|
314
|
+
# rdoc-file=lib/set.rb
|
|
315
|
+
# - include?(o)
|
|
316
|
+
# -->
|
|
118
317
|
# Returns true if the set contains the given object.
|
|
119
|
-
#
|
|
120
|
-
#
|
|
121
|
-
# do other Enumerables.
|
|
122
|
-
#
|
|
318
|
+
# Note that `include?` and `member?` do not test member
|
|
319
|
+
# equality using `==` as do other Enumerables.
|
|
123
320
|
# See also Enumerable#include?
|
|
124
321
|
#
|
|
125
322
|
def include?: (A) -> bool
|
|
126
323
|
|
|
324
|
+
# <!--
|
|
325
|
+
# rdoc-file=lib/set.rb
|
|
326
|
+
# - member?(o)
|
|
327
|
+
# -->
|
|
328
|
+
#
|
|
127
329
|
alias member? include?
|
|
128
330
|
|
|
129
|
-
#
|
|
130
|
-
#
|
|
131
|
-
# enum)
|
|
132
|
-
#
|
|
331
|
+
# <!--
|
|
332
|
+
# rdoc-file=lib/set.rb
|
|
333
|
+
# - ^(enum)
|
|
334
|
+
# -->
|
|
335
|
+
# Returns a new set containing elements exclusive between the set
|
|
336
|
+
# and the given enumerable object. `(set ^ enum)` is equivalent to
|
|
337
|
+
# `((set | enum) - (set & enum))`.
|
|
133
338
|
# Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
|
|
134
339
|
# Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
|
|
135
340
|
#
|
|
136
341
|
def ^: (_Each[A]) -> self
|
|
137
342
|
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
#
|
|
141
|
-
#
|
|
343
|
+
# <!--
|
|
344
|
+
# rdoc-file=lib/set.rb
|
|
345
|
+
# - classify() { |o| ... }
|
|
346
|
+
# -->
|
|
347
|
+
# Classifies the set by the return value of the given block and
|
|
348
|
+
# returns a hash of {value => set of elements} pairs. The block is
|
|
349
|
+
# called once for each element of the set, passing the element as
|
|
350
|
+
# parameter.
|
|
142
351
|
# require 'set'
|
|
143
352
|
# files = Set.new(Dir.glob("*.rb"))
|
|
144
353
|
# hash = files.classify { |f| File.mtime(f).year }
|
|
@@ -150,56 +359,92 @@ class Set[A]
|
|
|
150
359
|
#
|
|
151
360
|
def classify: [X] () { (A) -> X } -> Hash[X, self]
|
|
152
361
|
|
|
362
|
+
# <!--
|
|
363
|
+
# rdoc-file=lib/set.rb
|
|
364
|
+
# - clear()
|
|
365
|
+
# -->
|
|
153
366
|
# Removes all elements and returns self.
|
|
154
|
-
#
|
|
155
367
|
# set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
|
|
156
368
|
# set.clear #=> #<Set: {}>
|
|
157
369
|
# set #=> #<Set: {}>
|
|
158
370
|
#
|
|
159
371
|
def clear: () -> self
|
|
160
372
|
|
|
161
|
-
#
|
|
162
|
-
#
|
|
373
|
+
# <!--
|
|
374
|
+
# rdoc-file=lib/set.rb
|
|
375
|
+
# - collect!() { |o| ... }
|
|
376
|
+
# -->
|
|
377
|
+
# Replaces the elements with ones returned by `collect()`.
|
|
378
|
+
# Returns an enumerator if no block is given.
|
|
163
379
|
#
|
|
164
380
|
def collect!: () { (A) -> A } -> self
|
|
165
381
|
|
|
382
|
+
# <!--
|
|
383
|
+
# rdoc-file=lib/set.rb
|
|
384
|
+
# - map!()
|
|
385
|
+
# -->
|
|
386
|
+
#
|
|
166
387
|
alias map! collect!
|
|
167
388
|
|
|
168
|
-
#
|
|
169
|
-
#
|
|
389
|
+
# <!--
|
|
390
|
+
# rdoc-file=lib/set.rb
|
|
391
|
+
# - delete(o)
|
|
392
|
+
# -->
|
|
393
|
+
# Deletes the given object from the set and returns self. Use
|
|
394
|
+
# `subtract` to delete many items at once.
|
|
170
395
|
#
|
|
171
396
|
def delete: (A) -> self
|
|
172
397
|
|
|
173
|
-
#
|
|
174
|
-
#
|
|
398
|
+
# <!--
|
|
399
|
+
# rdoc-file=lib/set.rb
|
|
400
|
+
# - delete?(o)
|
|
401
|
+
# -->
|
|
402
|
+
# Deletes the given object from the set and returns self. If the
|
|
403
|
+
# object is not in the set, returns nil.
|
|
175
404
|
#
|
|
176
405
|
def delete?: (A) -> self?
|
|
177
406
|
|
|
178
|
-
#
|
|
179
|
-
#
|
|
407
|
+
# <!--
|
|
408
|
+
# rdoc-file=lib/set.rb
|
|
409
|
+
# - delete_if() { |o| ... }
|
|
410
|
+
# -->
|
|
411
|
+
# Deletes every element of the set for which block evaluates to
|
|
412
|
+
# true, and returns self. Returns an enumerator if no block is
|
|
413
|
+
# given.
|
|
180
414
|
#
|
|
181
415
|
def delete_if: () { (A) -> untyped } -> self
|
|
182
416
|
|
|
183
|
-
#
|
|
184
|
-
#
|
|
417
|
+
# <!--
|
|
418
|
+
# rdoc-file=lib/set.rb
|
|
419
|
+
# - reject!(&block)
|
|
420
|
+
# -->
|
|
421
|
+
# Equivalent to Set#delete_if, but returns nil if no changes were
|
|
422
|
+
# made. Returns an enumerator if no block is given.
|
|
185
423
|
#
|
|
186
424
|
def reject!: () { (A) -> untyped } -> self
|
|
187
425
|
|
|
188
|
-
#
|
|
189
|
-
#
|
|
190
|
-
#
|
|
426
|
+
# <!--
|
|
427
|
+
# rdoc-file=lib/set.rb
|
|
428
|
+
# - disjoint?(set)
|
|
429
|
+
# -->
|
|
430
|
+
# Returns true if the set and the given enumerable have
|
|
431
|
+
# no element in common. This method is the opposite of `intersect?`.
|
|
191
432
|
# Set[1, 2, 3].disjoint? Set[3, 4] #=> false
|
|
192
433
|
# Set[1, 2, 3].disjoint? Set[4, 5] #=> true
|
|
434
|
+
# Set[1, 2, 3].disjoint? [3, 4] #=> false
|
|
435
|
+
# Set[1, 2, 3].disjoint? 4..5 #=> true
|
|
193
436
|
#
|
|
194
437
|
def disjoint?: (self) -> bool
|
|
195
438
|
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#
|
|
199
|
-
#
|
|
200
|
-
#
|
|
201
|
-
#
|
|
202
|
-
#
|
|
439
|
+
# <!--
|
|
440
|
+
# rdoc-file=lib/set.rb
|
|
441
|
+
# - divide(&func)
|
|
442
|
+
# -->
|
|
443
|
+
# Divides the set into a set of subsets according to the commonality
|
|
444
|
+
# defined by the given block.
|
|
445
|
+
# If the arity of the block is 2, elements o1 and o2 are in common
|
|
446
|
+
# if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are
|
|
447
|
+
# in common if block.call(o1) == block.call(o2).
|
|
203
448
|
# require 'set'
|
|
204
449
|
# numbers = Set[1, 3, 4, 6, 9, 10, 11]
|
|
205
450
|
# set = numbers.divide { |i,j| (i - j).abs == 1 }
|
|
@@ -213,94 +458,163 @@ class Set[A]
|
|
|
213
458
|
def divide: () { (A, A) -> untyped } -> Set[self]
|
|
214
459
|
| () { (A) -> untyped } -> Set[self]
|
|
215
460
|
|
|
216
|
-
#
|
|
217
|
-
#
|
|
461
|
+
# <!--
|
|
462
|
+
# rdoc-file=lib/set.rb
|
|
463
|
+
# - each(&block)
|
|
464
|
+
# -->
|
|
465
|
+
# Calls the given block once for each element in the set, passing
|
|
466
|
+
# the element as parameter. Returns an enumerator if no block is
|
|
467
|
+
# given.
|
|
218
468
|
#
|
|
219
469
|
def each: () { (A) -> void } -> self
|
|
220
470
|
|
|
471
|
+
# <!--
|
|
472
|
+
# rdoc-file=lib/set.rb
|
|
473
|
+
# - empty?()
|
|
474
|
+
# -->
|
|
221
475
|
# Returns true if the set contains no elements.
|
|
222
476
|
#
|
|
223
477
|
def empty?: () -> bool
|
|
224
478
|
|
|
225
|
-
#
|
|
226
|
-
#
|
|
479
|
+
# <!--
|
|
480
|
+
# rdoc-file=lib/set.rb
|
|
481
|
+
# - flatten()
|
|
482
|
+
# -->
|
|
483
|
+
# Returns a new set that is a copy of the set, flattening each
|
|
484
|
+
# containing set recursively.
|
|
227
485
|
#
|
|
228
486
|
def flatten: () -> Set[untyped]
|
|
229
487
|
|
|
230
|
-
#
|
|
231
|
-
#
|
|
488
|
+
# <!--
|
|
489
|
+
# rdoc-file=lib/set.rb
|
|
490
|
+
# - intersect?(set)
|
|
491
|
+
# -->
|
|
492
|
+
# Returns true if the set and the given enumerable have at least one
|
|
493
|
+
# element in common.
|
|
232
494
|
# Set[1, 2, 3].intersect? Set[4, 5] #=> false
|
|
233
495
|
# Set[1, 2, 3].intersect? Set[3, 4] #=> true
|
|
496
|
+
# Set[1, 2, 3].intersect? 4..5 #=> false
|
|
497
|
+
# Set[1, 2, 3].intersect? [3, 4] #=> true
|
|
234
498
|
#
|
|
235
499
|
def intersect?: (self) -> bool
|
|
236
500
|
|
|
237
|
-
#
|
|
238
|
-
#
|
|
501
|
+
# <!--
|
|
502
|
+
# rdoc-file=lib/set.rb
|
|
503
|
+
# - keep_if() { |o| ... }
|
|
504
|
+
# -->
|
|
505
|
+
# Deletes every element of the set for which block evaluates to
|
|
506
|
+
# false, and returns self. Returns an enumerator if no block is
|
|
507
|
+
# given.
|
|
239
508
|
#
|
|
240
509
|
def keep_if: () { (A) -> untyped } -> self
|
|
241
510
|
|
|
511
|
+
# <!--
|
|
512
|
+
# rdoc-file=lib/set.rb
|
|
513
|
+
# - size()
|
|
514
|
+
# -->
|
|
242
515
|
# Returns the number of elements.
|
|
243
516
|
#
|
|
244
517
|
def size: () -> Integer
|
|
245
518
|
|
|
519
|
+
# <!--
|
|
520
|
+
# rdoc-file=lib/set.rb
|
|
521
|
+
# - length()
|
|
522
|
+
# -->
|
|
523
|
+
#
|
|
246
524
|
alias length size
|
|
247
525
|
|
|
248
|
-
#
|
|
249
|
-
#
|
|
526
|
+
# <!--
|
|
527
|
+
# rdoc-file=lib/set.rb
|
|
528
|
+
# - merge(enum)
|
|
529
|
+
# -->
|
|
530
|
+
# Merges the elements of the given enumerable object to the set and
|
|
531
|
+
# returns self.
|
|
250
532
|
#
|
|
251
533
|
def merge: (_Each[A]) -> self
|
|
252
534
|
|
|
535
|
+
# <!--
|
|
536
|
+
# rdoc-file=lib/set.rb
|
|
537
|
+
# - subset?(set)
|
|
538
|
+
# -->
|
|
253
539
|
# Returns true if the set is a subset of the given set.
|
|
254
540
|
#
|
|
255
541
|
def subset?: (self) -> bool
|
|
256
542
|
|
|
257
543
|
def proper_subst?: (self) -> bool
|
|
258
544
|
|
|
545
|
+
# <!--
|
|
546
|
+
# rdoc-file=lib/set.rb
|
|
547
|
+
# - superset?(set)
|
|
548
|
+
# -->
|
|
259
549
|
# Returns true if the set is a superset of the given set.
|
|
260
550
|
#
|
|
261
551
|
def superset?: (self) -> bool
|
|
262
552
|
|
|
553
|
+
# <!--
|
|
554
|
+
# rdoc-file=lib/set.rb
|
|
555
|
+
# - proper_superset?(set)
|
|
556
|
+
# -->
|
|
263
557
|
# Returns true if the set is a proper superset of the given set.
|
|
264
558
|
#
|
|
265
559
|
def proper_superset?: (self) -> bool
|
|
266
560
|
|
|
267
|
-
#
|
|
268
|
-
#
|
|
269
|
-
#
|
|
561
|
+
# <!--
|
|
562
|
+
# rdoc-file=lib/set.rb
|
|
563
|
+
# - replace(enum)
|
|
564
|
+
# -->
|
|
565
|
+
# Replaces the contents of the set with the contents of the given
|
|
566
|
+
# enumerable object and returns self.
|
|
270
567
|
# set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
|
|
271
568
|
# set.replace([1, 2]) #=> #<Set: {1, 2}>
|
|
272
569
|
# set #=> #<Set: {1, 2}>
|
|
273
570
|
#
|
|
274
571
|
def replace: (_Each[A]) -> self
|
|
275
572
|
|
|
276
|
-
#
|
|
277
|
-
#
|
|
278
|
-
#
|
|
573
|
+
# <!--
|
|
574
|
+
# rdoc-file=lib/set.rb
|
|
575
|
+
# - reset()
|
|
576
|
+
# -->
|
|
577
|
+
# Resets the internal state after modification to existing elements
|
|
578
|
+
# and returns self.
|
|
279
579
|
# Elements will be reindexed and deduplicated.
|
|
280
580
|
#
|
|
281
581
|
def reset: () -> self
|
|
282
582
|
|
|
283
|
-
#
|
|
284
|
-
#
|
|
583
|
+
# <!--
|
|
584
|
+
# rdoc-file=lib/set.rb
|
|
585
|
+
# - select!(&block)
|
|
586
|
+
# -->
|
|
587
|
+
# Equivalent to Set#keep_if, but returns nil if no changes were
|
|
588
|
+
# made. Returns an enumerator if no block is given.
|
|
285
589
|
#
|
|
286
590
|
def select!: () { (A) -> untyped } -> self?
|
|
287
591
|
|
|
288
|
-
#
|
|
289
|
-
#
|
|
592
|
+
# <!--
|
|
593
|
+
# rdoc-file=lib/set.rb
|
|
594
|
+
# - subtract(enum)
|
|
595
|
+
# -->
|
|
596
|
+
# Deletes every element that appears in the given enumerable object
|
|
597
|
+
# and returns self.
|
|
290
598
|
#
|
|
291
599
|
def subtract: (_Each[A]) -> self
|
|
292
600
|
|
|
293
|
-
#
|
|
294
|
-
#
|
|
601
|
+
# <!--
|
|
602
|
+
# rdoc-file=lib/set.rb
|
|
603
|
+
# - to_a()
|
|
604
|
+
# -->
|
|
605
|
+
# Converts the set to an array. The order of elements is uncertain.
|
|
295
606
|
# Set[1, 2].to_a #=> [1, 2]
|
|
296
607
|
# Set[1, 'c', :s].to_a #=> [1, "c", :s]
|
|
297
608
|
#
|
|
298
609
|
def to_a: () -> Array[A]
|
|
299
|
-
|
|
300
|
-
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
|
#
|