rbs 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +28 -0
  3. data/.gitignore +12 -0
  4. data/.rubocop.yml +15 -0
  5. data/BSDL +22 -0
  6. data/CHANGELOG.md +9 -0
  7. data/COPYING +56 -0
  8. data/Gemfile +6 -0
  9. data/README.md +93 -0
  10. data/Rakefile +142 -0
  11. data/bin/annotate-with-rdoc +157 -0
  12. data/bin/console +14 -0
  13. data/bin/query-rdoc +103 -0
  14. data/bin/setup +10 -0
  15. data/bin/sort +89 -0
  16. data/bin/test_runner.rb +16 -0
  17. data/docs/CONTRIBUTING.md +97 -0
  18. data/docs/sigs.md +148 -0
  19. data/docs/stdlib.md +152 -0
  20. data/docs/syntax.md +528 -0
  21. data/exe/rbs +7 -0
  22. data/lib/rbs.rb +64 -0
  23. data/lib/rbs/ast/annotation.rb +27 -0
  24. data/lib/rbs/ast/comment.rb +27 -0
  25. data/lib/rbs/ast/declarations.rb +395 -0
  26. data/lib/rbs/ast/members.rb +362 -0
  27. data/lib/rbs/buffer.rb +50 -0
  28. data/lib/rbs/builtin_names.rb +55 -0
  29. data/lib/rbs/cli.rb +558 -0
  30. data/lib/rbs/constant.rb +26 -0
  31. data/lib/rbs/constant_table.rb +150 -0
  32. data/lib/rbs/definition.rb +170 -0
  33. data/lib/rbs/definition_builder.rb +919 -0
  34. data/lib/rbs/environment.rb +281 -0
  35. data/lib/rbs/environment_loader.rb +136 -0
  36. data/lib/rbs/environment_walker.rb +124 -0
  37. data/lib/rbs/errors.rb +187 -0
  38. data/lib/rbs/location.rb +102 -0
  39. data/lib/rbs/method_type.rb +123 -0
  40. data/lib/rbs/namespace.rb +91 -0
  41. data/lib/rbs/parser.y +1344 -0
  42. data/lib/rbs/prototype/rb.rb +553 -0
  43. data/lib/rbs/prototype/rbi.rb +587 -0
  44. data/lib/rbs/prototype/runtime.rb +381 -0
  45. data/lib/rbs/substitution.rb +46 -0
  46. data/lib/rbs/test.rb +26 -0
  47. data/lib/rbs/test/errors.rb +61 -0
  48. data/lib/rbs/test/hook.rb +294 -0
  49. data/lib/rbs/test/setup.rb +58 -0
  50. data/lib/rbs/test/spy.rb +325 -0
  51. data/lib/rbs/test/test_helper.rb +183 -0
  52. data/lib/rbs/test/type_check.rb +254 -0
  53. data/lib/rbs/type_name.rb +70 -0
  54. data/lib/rbs/types.rb +936 -0
  55. data/lib/rbs/variance_calculator.rb +138 -0
  56. data/lib/rbs/vendorer.rb +47 -0
  57. data/lib/rbs/version.rb +3 -0
  58. data/lib/rbs/writer.rb +269 -0
  59. data/lib/ruby/signature.rb +7 -0
  60. data/rbs.gemspec +46 -0
  61. data/stdlib/abbrev/abbrev.rbs +60 -0
  62. data/stdlib/base64/base64.rbs +71 -0
  63. data/stdlib/benchmark/benchmark.rbs +372 -0
  64. data/stdlib/builtin/array.rbs +1997 -0
  65. data/stdlib/builtin/basic_object.rbs +280 -0
  66. data/stdlib/builtin/binding.rbs +177 -0
  67. data/stdlib/builtin/builtin.rbs +45 -0
  68. data/stdlib/builtin/class.rbs +145 -0
  69. data/stdlib/builtin/comparable.rbs +116 -0
  70. data/stdlib/builtin/complex.rbs +400 -0
  71. data/stdlib/builtin/constants.rbs +37 -0
  72. data/stdlib/builtin/data.rbs +5 -0
  73. data/stdlib/builtin/deprecated.rbs +2 -0
  74. data/stdlib/builtin/dir.rbs +413 -0
  75. data/stdlib/builtin/encoding.rbs +607 -0
  76. data/stdlib/builtin/enumerable.rbs +404 -0
  77. data/stdlib/builtin/enumerator.rbs +260 -0
  78. data/stdlib/builtin/errno.rbs +781 -0
  79. data/stdlib/builtin/errors.rbs +582 -0
  80. data/stdlib/builtin/exception.rbs +194 -0
  81. data/stdlib/builtin/false_class.rbs +40 -0
  82. data/stdlib/builtin/fiber.rbs +68 -0
  83. data/stdlib/builtin/fiber_error.rbs +12 -0
  84. data/stdlib/builtin/file.rbs +1076 -0
  85. data/stdlib/builtin/file_test.rbs +59 -0
  86. data/stdlib/builtin/float.rbs +696 -0
  87. data/stdlib/builtin/gc.rbs +243 -0
  88. data/stdlib/builtin/hash.rbs +1029 -0
  89. data/stdlib/builtin/integer.rbs +707 -0
  90. data/stdlib/builtin/io.rbs +683 -0
  91. data/stdlib/builtin/kernel.rbs +576 -0
  92. data/stdlib/builtin/marshal.rbs +161 -0
  93. data/stdlib/builtin/match_data.rbs +271 -0
  94. data/stdlib/builtin/math.rbs +369 -0
  95. data/stdlib/builtin/method.rbs +185 -0
  96. data/stdlib/builtin/module.rbs +1104 -0
  97. data/stdlib/builtin/nil_class.rbs +82 -0
  98. data/stdlib/builtin/numeric.rbs +409 -0
  99. data/stdlib/builtin/object.rbs +824 -0
  100. data/stdlib/builtin/proc.rbs +429 -0
  101. data/stdlib/builtin/process.rbs +1227 -0
  102. data/stdlib/builtin/random.rbs +267 -0
  103. data/stdlib/builtin/range.rbs +226 -0
  104. data/stdlib/builtin/rational.rbs +424 -0
  105. data/stdlib/builtin/rb_config.rbs +57 -0
  106. data/stdlib/builtin/regexp.rbs +1083 -0
  107. data/stdlib/builtin/ruby_vm.rbs +14 -0
  108. data/stdlib/builtin/signal.rbs +55 -0
  109. data/stdlib/builtin/string.rbs +1901 -0
  110. data/stdlib/builtin/string_io.rbs +284 -0
  111. data/stdlib/builtin/struct.rbs +40 -0
  112. data/stdlib/builtin/symbol.rbs +228 -0
  113. data/stdlib/builtin/thread.rbs +1108 -0
  114. data/stdlib/builtin/thread_group.rbs +23 -0
  115. data/stdlib/builtin/time.rbs +1047 -0
  116. data/stdlib/builtin/trace_point.rbs +290 -0
  117. data/stdlib/builtin/true_class.rbs +46 -0
  118. data/stdlib/builtin/unbound_method.rbs +153 -0
  119. data/stdlib/builtin/warning.rbs +17 -0
  120. data/stdlib/coverage/coverage.rbs +62 -0
  121. data/stdlib/csv/csv.rbs +773 -0
  122. data/stdlib/erb/erb.rbs +392 -0
  123. data/stdlib/find/find.rbs +40 -0
  124. data/stdlib/ipaddr/ipaddr.rbs +247 -0
  125. data/stdlib/json/json.rbs +335 -0
  126. data/stdlib/pathname/pathname.rbs +1093 -0
  127. data/stdlib/prime/integer-extension.rbs +23 -0
  128. data/stdlib/prime/prime.rbs +188 -0
  129. data/stdlib/securerandom/securerandom.rbs +9 -0
  130. data/stdlib/set/set.rbs +301 -0
  131. data/stdlib/tmpdir/tmpdir.rbs +53 -0
  132. metadata +292 -0
@@ -0,0 +1,23 @@
1
+ extension Integer (Prime)
2
+ # Iterates the given block over all prime numbers.
3
+ #
4
+ # See Prime#each for more details.
5
+ #
6
+ def self.each_prime: (Integer) { (Integer) -> void } -> void
7
+
8
+ # Re-composes a prime factorization and returns the product.
9
+ #
10
+ # See Prime#int_from_prime_division for more details.
11
+ #
12
+ def self.from_prime_division: (Array[[ String ]]) -> Integer
13
+
14
+ # Returns the factorization of `self`.
15
+ #
16
+ # See Prime#prime_division for more details.
17
+ #
18
+ def prime_division: (?Prime::PseudoPrimeGenerator) -> Array[[ Integer, Integer ]]
19
+
20
+ # Returns true if `self` is a prime number, else returns false.
21
+ #
22
+ def prime?: () -> bool
23
+ end
@@ -0,0 +1,188 @@
1
+ # The set of all prime numbers.
2
+ #
3
+ # ## Example
4
+ #
5
+ # Prime.each(100) do |prime|
6
+ # p prime #=> 2, 3, 5, 7, 11, ...., 97
7
+ # end
8
+ #
9
+ # Prime is Enumerable:
10
+ #
11
+ # Prime.first 5 # => [2, 3, 5, 7, 11]
12
+ #
13
+ # ## Retrieving the instance
14
+ #
15
+ # For convenience, each instance method of `Prime`.instance can be accessed as a
16
+ # class method of `Prime`.
17
+ #
18
+ # e.g.
19
+ # Prime.instance.prime?(2) #=> true
20
+ # Prime.prime?(2) #=> true
21
+ #
22
+ # ## Generators
23
+ #
24
+ # A "generator" provides an implementation of enumerating pseudo-prime numbers
25
+ # and it remembers the position of enumeration and upper bound. Furthermore, it
26
+ # is an external iterator of prime enumeration which is compatible with an
27
+ # Enumerator.
28
+ #
29
+ # `Prime`::`PseudoPrimeGenerator` is the base class for generators. There are
30
+ # few implementations of generator.
31
+ #
32
+ # `Prime`::`EratosthenesGenerator`
33
+ # : Uses eratosthenes' sieve.
34
+ # `Prime`::`TrialDivisionGenerator`
35
+ # : Uses the trial division method.
36
+ # `Prime`::`Generator23`
37
+ # : Generates all positive integers which are not divisible by either 2 or 3.
38
+ # This sequence is very bad as a pseudo-prime sequence. But this is faster
39
+ # and uses much less memory than the other generators. So, it is suitable
40
+ # for factorizing an integer which is not large but has many prime factors.
41
+ # e.g. for Prime#prime? .
42
+ #
43
+ #
44
+ class Prime
45
+ # Iterates the given block over all prime numbers.
46
+ #
47
+ # ## Parameters
48
+ #
49
+ # `ubound`
50
+ # : Optional. An arbitrary positive number. The upper bound of enumeration.
51
+ # The method enumerates prime numbers infinitely if `ubound` is nil.
52
+ # `generator`
53
+ # : Optional. An implementation of pseudo-prime generator.
54
+ #
55
+ #
56
+ # ## Return value
57
+ #
58
+ # An evaluated value of the given block at the last time. Or an enumerator which
59
+ # is compatible to an `Enumerator` if no block given.
60
+ #
61
+ # ## Description
62
+ #
63
+ # Calls `block` once for each prime number, passing the prime as a parameter.
64
+ #
65
+ # `ubound`
66
+ # : Upper bound of prime numbers. The iterator stops after it yields all prime
67
+ # numbers p <= `ubound`.
68
+ #
69
+ def self?.each: (?Integer? ubound, ?PseudoPrimeGenerator generator) { (Integer) -> void } -> void
70
+ | (?Integer? ubound, ?PseudoPrimeGenerator generator) -> PseudoPrimeGenerator
71
+
72
+ # Re-composes a prime factorization and returns the product.
73
+ #
74
+ # ## Parameters
75
+ # `pd`
76
+ # : Array of pairs of integers. The each internal pair consists of a prime
77
+ # number -- a prime factor -- and a natural number -- an exponent.
78
+ #
79
+ #
80
+ # ## Example
81
+ # For `[[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]]`, it returns:
82
+ #
83
+ # p_1**e_1 * p_2**e_2 * .... * p_n**e_n.
84
+ #
85
+ # Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
86
+ #
87
+ def self?.int_from_prime_division: (Array[[ Integer, Integer ]]) -> Integer
88
+
89
+ # Returns true if `value` is a prime number, else returns false.
90
+ #
91
+ # ## Parameters
92
+ #
93
+ # `value`
94
+ # : an arbitrary integer to be checked.
95
+ # `generator`
96
+ # : optional. A pseudo-prime generator.
97
+ #
98
+ def self?.prime?: (Integer value, ?PseudoPrimeGenerator generator) -> bool
99
+
100
+ # Returns the factorization of `value`.
101
+ #
102
+ # ## Parameters
103
+ # `value`
104
+ # : An arbitrary integer.
105
+ # `generator`
106
+ # : Optional. A pseudo-prime generator. `generator`.succ must return the next
107
+ # pseudo-prime number in the ascending order. It must generate all prime
108
+ # numbers, but may also generate non prime numbers too.
109
+ #
110
+ #
111
+ # ### Exceptions
112
+ # `ZeroDivisionError`
113
+ # : when `value` is zero.
114
+ #
115
+ #
116
+ # ## Example
117
+ # For an arbitrary integer:
118
+ #
119
+ # n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
120
+ #
121
+ # prime_division(n) returns:
122
+ #
123
+ # [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
124
+ #
125
+ # Prime.prime_division(12) #=> [[2,2], [3,1]]
126
+ #
127
+ def self?.prime_division: (Integer, ?PseudoPrimeGenerator generator) -> Array[[ Integer, Integer ]]
128
+
129
+ # Returns the singleton instance.
130
+ #
131
+ def self.instance: () -> Prime
132
+ end
133
+
134
+ # An abstract class for enumerating pseudo-prime numbers.
135
+ #
136
+ # Concrete subclasses should override succ, next, rewind.
137
+ #
138
+ class Prime::PseudoPrimeGenerator
139
+ def initialize: (?Integer?) -> void
140
+
141
+ include Enumerable[Integer, void]
142
+
143
+ attr_accessor upper_bound (): Integer?
144
+
145
+ # Iterates the given block for each prime number.
146
+ #
147
+ def each: () { (Integer) -> void } -> void
148
+
149
+ # alias of `succ`.
150
+ #
151
+ def next: () -> Integer
152
+
153
+ # Rewinds the internal position for enumeration.
154
+ #
155
+ # See `Enumerator`#rewind.
156
+ #
157
+ def rewind: () -> void
158
+
159
+ def size: () -> Float
160
+
161
+ # returns the next pseudo-prime number, and move the internal position forward.
162
+ #
163
+ # `PseudoPrimeGenerator`#succ raises `NotImplementedError`.
164
+ #
165
+ def succ: () -> Integer
166
+ end
167
+
168
+ # An implementation of `PseudoPrimeGenerator`.
169
+ #
170
+ # Uses `EratosthenesSieve`.
171
+ #
172
+ class Prime::EratosthenesGenerator < PseudoPrimeGenerator
173
+ end
174
+
175
+ # An implementation of `PseudoPrimeGenerator` which uses a prime table generated
176
+ # by trial division.
177
+ #
178
+ class Prime::TrialDivisionGenerator < PseudoPrimeGenerator
179
+ end
180
+
181
+ # Generates all integers which are greater than 2 and are not divisible by
182
+ # either 2 or 3.
183
+ #
184
+ # This is a pseudo-prime generator, suitable on checking primality of an integer
185
+ # by brute force method.
186
+ #
187
+ class Prime::Generator23 < PseudoPrimeGenerator
188
+ end
@@ -0,0 +1,9 @@
1
+ module SecureRandom
2
+ def self.alphanumeric: (?Integer?) -> String
3
+ def self.base64: (?Integer?) -> String
4
+ def self.hex: (?Integer?) -> String
5
+ def self.random_bytes: (?Integer?) -> String
6
+ def self.random_number: (?Integer?) -> (Integer | Float)
7
+ def self.urlsafe_base64: (?Integer?, ?bool?) -> String
8
+ def self.uuid: () -> String
9
+ end
@@ -0,0 +1,301 @@
1
+ # Set implements a collection of unordered values with no duplicates. This is a
2
+ # hybrid of Array's intuitive inter-operation facilities and Hash's fast lookup.
3
+ #
4
+ # Set is easy to use with Enumerable objects (implementing `each`). Most of the
5
+ # initializer methods and binary operators accept generic Enumerable objects
6
+ # besides sets and arrays. An Enumerable object can be converted to Set using
7
+ # the `to_set` method.
8
+ #
9
+ # Set uses Hash as storage, so you must note the following points:
10
+ #
11
+ # * Equality of elements is determined according to Object#eql? and
12
+ # Object#hash. Use Set#compare_by_identity to make a set compare its
13
+ # elements by their identity.
14
+ # * Set assumes that the identity of each element does not change while it is
15
+ # stored. Modifying an element of a set will render the set to an
16
+ # unreliable state.
17
+ # * When a string is to be stored, a frozen copy of the string is stored
18
+ # instead unless the original string is already frozen.
19
+ #
20
+ #
21
+ # ## Comparison
22
+ #
23
+ # The comparison operators <, >, <=, and >= are implemented as shorthand for the
24
+ # {proper_,}{subset?,superset?} methods. However, the <=> operator is
25
+ # intentionally left out because not every pair of sets is comparable ({x, y}
26
+ # vs. {x, z} for example).
27
+ #
28
+ # ## Example
29
+ #
30
+ # require 'set'
31
+ # s1 = Set[1, 2] #=> #<Set: {1, 2}>
32
+ # s2 = [1, 2].to_set #=> #<Set: {1, 2}>
33
+ # s1 == s2 #=> true
34
+ # s1.add("foo") #=> #<Set: {1, 2, "foo"}>
35
+ # s1.merge([2, 6]) #=> #<Set: {1, 2, "foo", 6}>
36
+ # s1.subset?(s2) #=> false
37
+ # s2.subset?(s1) #=> true
38
+ #
39
+ # ## Contact
40
+ #
41
+ # - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
42
+ #
43
+ class Set[A]
44
+ # Creates a new set containing the elements of the given enumerable object.
45
+ #
46
+ # If a block is given, the elements of enum are preprocessed by the given block.
47
+ #
48
+ # Set.new([1, 2]) #=> #<Set: {1, 2}>
49
+ # Set.new([1, 2, 1]) #=> #<Set: {1, 2}>
50
+ # Set.new([1, 'c', :s]) #=> #<Set: {1, "c", :s}>
51
+ # Set.new(1..5) #=> #<Set: {1, 2, 3, 4, 5}>
52
+ # Set.new([1, 2, 3]) { |x| x * x } #=> #<Set: {1, 4, 9}>
53
+ #
54
+ def initialize: (_Each[A, untyped]) -> untyped
55
+ | [X] (_Each[X, untyped]) { (X) -> A } -> untyped
56
+ | (?nil) -> untyped
57
+
58
+ # Creates a new set containing the given objects.
59
+ #
60
+ # Set[1, 2] # => #<Set: {1, 2}>
61
+ # Set[1, 2, 1] # => #<Set: {1, 2}>
62
+ # Set[1, 'c', :s] # => #<Set: {1, "c", :s}>
63
+ #
64
+ def self.[]: [X] (*X) -> Set[X]
65
+
66
+ # Returns a new set containing elements common to the set and the given
67
+ # enumerable object.
68
+ #
69
+ # Set[1, 3, 5] & Set[3, 2, 1] #=> #<Set: {3, 1}>
70
+ # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
71
+ #
72
+ def &: (_Each[A, untyped]) -> self
73
+
74
+ alias intersection &
75
+
76
+ # Returns a new set built by merging the set and the elements of the given
77
+ # enumerable object.
78
+ #
79
+ # Set[1, 2, 3] | Set[2, 4, 5] #=> #<Set: {1, 2, 3, 4, 5}>
80
+ # Set[1, 5, 'z'] | (1..6) #=> #<Set: {1, 5, "z", 2, 3, 4, 6}>
81
+ #
82
+ def |: (_Each[A, untyped]) -> self
83
+
84
+ alias union |
85
+
86
+ alias + |
87
+
88
+ # Returns a new set built by duplicating the set, removing every element that
89
+ # appears in the given enumerable object.
90
+ #
91
+ # Set[1, 3, 5] - Set[1, 5] #=> #<Set: {3}>
92
+ # Set['a', 'b', 'z'] - ['a', 'c'] #=> #<Set: {"b", "z"}>
93
+ #
94
+ def -: (_Each[A, untyped]) -> self
95
+
96
+ alias difference -
97
+
98
+ # Adds the given object to the set and returns self. Use `merge` to add many
99
+ # elements at once.
100
+ #
101
+ # Set[1, 2].add(3) #=> #<Set: {1, 2, 3}>
102
+ # Set[1, 2].add([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
103
+ # Set[1, 2].add(2) #=> #<Set: {1, 2}>
104
+ #
105
+ def add: (A) -> self
106
+
107
+ alias << add
108
+
109
+ # Adds the given object to the set and returns self. If the object is already
110
+ # in the set, returns nil.
111
+ #
112
+ # Set[1, 2].add?(3) #=> #<Set: {1, 2, 3}>
113
+ # Set[1, 2].add?([3, 4]) #=> #<Set: {1, 2, [3, 4]}>
114
+ # Set[1, 2].add?(2) #=> nil
115
+ #
116
+ def add?: (A) -> self?
117
+
118
+ # Returns true if the set contains the given object.
119
+ #
120
+ # Note that `include?` and `member?` do not test member equality using `==` as
121
+ # do other Enumerables.
122
+ #
123
+ # See also Enumerable#include?
124
+ #
125
+ def include?: (untyped) -> bool
126
+
127
+ alias member? include?
128
+
129
+ # Returns a new set containing elements exclusive between the set and the given
130
+ # enumerable object. (set ^ enum) is equivalent to ((set | enum) - (set &
131
+ # enum)).
132
+ #
133
+ # Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
134
+ # Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
135
+ #
136
+ def ^: (_Each[A, untyped]) -> self
137
+
138
+ # Classifies the set by the return value of the given block and returns a hash
139
+ # of {value => set of elements} pairs. The block is called once for each
140
+ # element of the set, passing the element as parameter.
141
+ #
142
+ # require 'set'
143
+ # files = Set.new(Dir.glob("*.rb"))
144
+ # hash = files.classify { |f| File.mtime(f).year }
145
+ # hash #=> {2000=>#<Set: {"a.rb", "b.rb"}>,
146
+ # # 2001=>#<Set: {"c.rb", "d.rb", "e.rb"}>,
147
+ # # 2002=>#<Set: {"f.rb"}>}
148
+ #
149
+ # Returns an enumerator if no block is given.
150
+ #
151
+ def classify: [X] () { (A) -> X } -> Hash[X, self]
152
+
153
+ # Removes all elements and returns self.
154
+ #
155
+ # set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
156
+ # set.clear #=> #<Set: {}>
157
+ # set #=> #<Set: {}>
158
+ #
159
+ def clear: () -> self
160
+
161
+ # Replaces the elements with ones returned by collect(). Returns an enumerator
162
+ # if no block is given.
163
+ #
164
+ def collect!: () { (A) -> A } -> self
165
+
166
+ alias map! collect!
167
+
168
+ # Deletes the given object from the set and returns self. Use `subtract` to
169
+ # delete many items at once.
170
+ #
171
+ def delete: (untyped) -> self
172
+
173
+ # Deletes the given object from the set and returns self. If the object is not
174
+ # in the set, returns nil.
175
+ #
176
+ def delete?: (untyped) -> self?
177
+
178
+ # Deletes every element of the set for which block evaluates to true, and
179
+ # returns self. Returns an enumerator if no block is given.
180
+ #
181
+ def delete_if: () { (A) -> untyped } -> self
182
+
183
+ # Equivalent to Set#delete_if, but returns nil if no changes were made. Returns
184
+ # an enumerator if no block is given.
185
+ #
186
+ def reject!: () { (A) -> untyped } -> self
187
+
188
+ # Returns true if the set and the given set have no element in common. This
189
+ # method is the opposite of `intersect?`.
190
+ #
191
+ # Set[1, 2, 3].disjoint? Set[3, 4] #=> false
192
+ # Set[1, 2, 3].disjoint? Set[4, 5] #=> true
193
+ #
194
+ def disjoint?: (self) -> bool
195
+
196
+ # Divides the set into a set of subsets according to the commonality defined by
197
+ # the given block.
198
+ #
199
+ # If the arity of the block is 2, elements o1 and o2 are in common if
200
+ # block.call(o1, o2) is true. Otherwise, elements o1 and o2 are in common if
201
+ # block.call(o1) == block.call(o2).
202
+ #
203
+ # require 'set'
204
+ # numbers = Set[1, 3, 4, 6, 9, 10, 11]
205
+ # set = numbers.divide { |i,j| (i - j).abs == 1 }
206
+ # set #=> #<Set: {#<Set: {1}>,
207
+ # # #<Set: {11, 9, 10}>,
208
+ # # #<Set: {3, 4}>,
209
+ # # #<Set: {6}>}>
210
+ #
211
+ # Returns an enumerator if no block is given.
212
+ #
213
+ def divide: () { (A, A) -> untyped } -> Set[self]
214
+ | () { (A) -> untyped } -> Set[self]
215
+
216
+ # Calls the given block once for each element in the set, passing the element as
217
+ # parameter. Returns an enumerator if no block is given.
218
+ #
219
+ def each: () { (A) -> void } -> self
220
+
221
+ # Returns true if the set contains no elements.
222
+ #
223
+ def empty?: () -> bool
224
+
225
+ # Returns a new set that is a copy of the set, flattening each containing set
226
+ # recursively.
227
+ #
228
+ def flatten: () -> Set[untyped]
229
+
230
+ # Returns true if the set and the given set have at least one element in common.
231
+ #
232
+ # Set[1, 2, 3].intersect? Set[4, 5] #=> false
233
+ # Set[1, 2, 3].intersect? Set[3, 4] #=> true
234
+ #
235
+ def intersect?: () -> bool
236
+
237
+ # Deletes every element of the set for which block evaluates to false, and
238
+ # returns self. Returns an enumerator if no block is given.
239
+ #
240
+ def keep_if: () { (A) -> untyped } -> self
241
+
242
+ # Returns the number of elements.
243
+ #
244
+ def size: () -> Integer
245
+
246
+ alias length size
247
+
248
+ # Merges the elements of the given enumerable object to the set and returns
249
+ # self.
250
+ #
251
+ def merge: (_Each[A, untyped]) -> self
252
+
253
+ # Returns true if the set is a subset of the given set.
254
+ #
255
+ def subset?: (self) -> bool
256
+
257
+ def proper_subst?: (self) -> bool
258
+
259
+ # Returns true if the set is a superset of the given set.
260
+ #
261
+ def superset?: (self) -> bool
262
+
263
+ # Returns true if the set is a proper superset of the given set.
264
+ #
265
+ def proper_superset?: (self) -> bool
266
+
267
+ # Replaces the contents of the set with the contents of the given enumerable
268
+ # object and returns self.
269
+ #
270
+ # set = Set[1, 'c', :s] #=> #<Set: {1, "c", :s}>
271
+ # set.replace([1, 2]) #=> #<Set: {1, 2}>
272
+ # set #=> #<Set: {1, 2}>
273
+ #
274
+ def replace: (_Each[A, untyped]) -> self
275
+
276
+ # Resets the internal state after modification to existing elements and returns
277
+ # self.
278
+ #
279
+ # Elements will be reindexed and deduplicated.
280
+ #
281
+ def reset: () -> self
282
+
283
+ # Equivalent to Set#keep_if, but returns nil if no changes were made. Returns an
284
+ # enumerator if no block is given.
285
+ #
286
+ def select!: () { (A) -> untyped } -> self?
287
+
288
+ # Deletes every element that appears in the given enumerable object and returns
289
+ # self.
290
+ #
291
+ def subtract: (_Each[A, untyped]) -> self
292
+
293
+ # Converts the set to an array. The order of elements is uncertain.
294
+ #
295
+ # Set[1, 2].to_a #=> [1, 2]
296
+ # Set[1, 'c', :s].to_a #=> [1, "c", :s]
297
+ #
298
+ def to_a: () -> Array[A]
299
+
300
+ include Enumerable[A, self]
301
+ end