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