rbs 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/docs/syntax.md +50 -6
- data/lib/rbs/definition_builder.rb +2 -2
- data/lib/rbs/parser.rb +98 -96
- data/lib/rbs/parser.y +3 -1
- data/lib/rbs/prototype/rb.rb +38 -6
- data/lib/rbs/prototype/runtime.rb +17 -7
- data/lib/rbs/test/hook.rb +2 -0
- data/lib/rbs/test/tester.rb +4 -1
- data/lib/rbs/test/type_check.rb +10 -4
- data/lib/rbs/version.rb +1 -1
- data/sig/constant_table.rbs +1 -1
- data/sig/declarations.rbs +1 -1
- data/sig/definition.rbs +1 -1
- data/sig/environment_loader.rbs +3 -3
- data/sig/members.rbs +2 -2
- data/sig/method_types.rbs +1 -1
- data/sig/namespace.rbs +1 -1
- data/stdlib/base64/base64.rbs +1 -1
- data/stdlib/builtin/array.rbs +124 -120
- data/stdlib/builtin/builtin.rbs +28 -0
- data/stdlib/builtin/enumerable.rbs +26 -20
- data/stdlib/builtin/errors.rbs +1 -1
- data/stdlib/builtin/gc.rbs +2 -2
- data/stdlib/builtin/hash.rbs +7 -7
- data/stdlib/builtin/io.rbs +5 -5
- data/stdlib/builtin/kernel.rbs +1 -85
- data/stdlib/builtin/module.rbs +13 -13
- data/stdlib/builtin/object.rbs +1 -1
- data/stdlib/builtin/random.rbs +1 -1
- data/stdlib/builtin/range.rbs +2 -2
- data/stdlib/builtin/string.rbs +6 -6
- data/stdlib/builtin/string_io.rbs +7 -7
- data/stdlib/builtin/struct.rbs +1 -1
- data/stdlib/builtin/symbol.rbs +1 -1
- data/stdlib/builtin/thread.rbs +4 -4
- data/stdlib/builtin/true_class.rbs +1 -1
- data/stdlib/coverage/coverage.rbs +2 -2
- data/stdlib/csv/csv.rbs +1 -1
- data/stdlib/date/date.rbs +2 -2
- data/stdlib/date/date_time.rbs +1 -1
- data/stdlib/find/find.rbs +2 -2
- data/stdlib/logger/log_device.rbs +1 -1
- data/stdlib/logger/logger.rbs +1 -1
- data/stdlib/pathname/pathname.rbs +39 -39
- data/stdlib/pstore/pstore.rbs +287 -0
- data/stdlib/pty/pty.rbs +1 -1
- data/stdlib/uri/generic.rbs +1 -1
- metadata +3 -2
data/lib/rbs/parser.y
CHANGED
@@ -475,6 +475,8 @@ rule
|
|
475
475
|
|
476
476
|
method_type:
|
477
477
|
start_merged_scope type_params params_opt block_opt kARROW simple_type {
|
478
|
+
reset_variable_scope
|
479
|
+
|
478
480
|
location = (val[1] || val[2] || val[3] || val[4]).location + val[5].location
|
479
481
|
type_params = val[1]&.value || []
|
480
482
|
|
@@ -875,7 +877,7 @@ rule
|
|
875
877
|
required_keywords: {},
|
876
878
|
optional_keywords: {},
|
877
879
|
rest_keywords: nil,
|
878
|
-
return_type: val[
|
880
|
+
return_type: val[1]
|
879
881
|
)
|
880
882
|
|
881
883
|
result = LocatedValue.new(value: type, location: location)
|
data/lib/rbs/prototype/rb.rb
CHANGED
@@ -135,6 +135,18 @@ module RBS
|
|
135
135
|
|
136
136
|
decls.push member unless decls.include?(member)
|
137
137
|
|
138
|
+
when :ALIAS
|
139
|
+
new_name, old_name = node.children.map { |c| literal_to_symbol(c) }
|
140
|
+
member = AST::Members::Alias.new(
|
141
|
+
new_name: new_name,
|
142
|
+
old_name: old_name,
|
143
|
+
kind: singleton ? :singleton : :instance,
|
144
|
+
annotations: [],
|
145
|
+
location: nil,
|
146
|
+
comment: comments[node.first_lineno - 1],
|
147
|
+
)
|
148
|
+
decls.push member unless decls.include?(member)
|
149
|
+
|
138
150
|
when :FCALL
|
139
151
|
# Inside method definition cannot reach here.
|
140
152
|
args = node.children[1]&.children || []
|
@@ -166,9 +178,9 @@ module RBS
|
|
166
178
|
end
|
167
179
|
when :attr_reader
|
168
180
|
args.each do |arg|
|
169
|
-
if arg
|
181
|
+
if arg && (name = literal_to_symbol(arg))
|
170
182
|
decls << AST::Members::AttrReader.new(
|
171
|
-
name:
|
183
|
+
name: name,
|
172
184
|
ivar_name: nil,
|
173
185
|
type: Types::Bases::Any.new(location: nil),
|
174
186
|
location: nil,
|
@@ -179,9 +191,9 @@ module RBS
|
|
179
191
|
end
|
180
192
|
when :attr_accessor
|
181
193
|
args.each do |arg|
|
182
|
-
if arg
|
194
|
+
if arg && (name = literal_to_symbol(arg))
|
183
195
|
decls << AST::Members::AttrAccessor.new(
|
184
|
-
name:
|
196
|
+
name: name,
|
185
197
|
ivar_name: nil,
|
186
198
|
type: Types::Bases::Any.new(location: nil),
|
187
199
|
location: nil,
|
@@ -192,9 +204,9 @@ module RBS
|
|
192
204
|
end
|
193
205
|
when :attr_writer
|
194
206
|
args.each do |arg|
|
195
|
-
if arg
|
207
|
+
if arg && (name = literal_to_symbol(arg))
|
196
208
|
decls << AST::Members::AttrWriter.new(
|
197
|
-
name:
|
209
|
+
name: name,
|
198
210
|
ivar_name: nil,
|
199
211
|
type: Types::Bases::Any.new(location: nil),
|
200
212
|
location: nil,
|
@@ -203,6 +215,17 @@ module RBS
|
|
203
215
|
)
|
204
216
|
end
|
205
217
|
end
|
218
|
+
when :alias_method
|
219
|
+
if args[0] && args[1] && (new_name = literal_to_symbol(args[0])) && (old_name = literal_to_symbol(args[1]))
|
220
|
+
decls << AST::Members::Alias.new(
|
221
|
+
new_name: new_name,
|
222
|
+
old_name: old_name,
|
223
|
+
kind: singleton ? :singleton : :instance,
|
224
|
+
annotations: [],
|
225
|
+
location: nil,
|
226
|
+
comment: comments[node.first_lineno - 1],
|
227
|
+
)
|
228
|
+
end
|
206
229
|
end
|
207
230
|
|
208
231
|
each_child node do |child|
|
@@ -248,6 +271,15 @@ module RBS
|
|
248
271
|
end
|
249
272
|
end
|
250
273
|
|
274
|
+
def literal_to_symbol(node)
|
275
|
+
case node.type
|
276
|
+
when :LIT
|
277
|
+
node.children[0] if node.children[0].is_a?(Symbol)
|
278
|
+
when :STR
|
279
|
+
node.children[0].to_sym
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
251
283
|
def each_node(nodes)
|
252
284
|
nodes.each do |child|
|
253
285
|
if child.is_a?(RubyVM::AbstractSyntaxTree::Node)
|
@@ -17,11 +17,13 @@ module RBS
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def target?(const)
|
20
|
+
name = const_name(const)
|
21
|
+
|
20
22
|
patterns.any? do |pattern|
|
21
23
|
if pattern.end_with?("*")
|
22
|
-
(
|
24
|
+
(name || "").start_with?(pattern.chop)
|
23
25
|
else
|
24
|
-
|
26
|
+
name == pattern
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
@@ -37,7 +39,7 @@ module RBS
|
|
37
39
|
def decls
|
38
40
|
unless @decls
|
39
41
|
@decls = []
|
40
|
-
ObjectSpace.each_object(Module).select {|mod| target?(mod) }.sort_by(
|
42
|
+
ObjectSpace.each_object(Module).select {|mod| target?(mod) }.sort_by{|mod| const_name(mod) }.each do |mod|
|
41
43
|
case mod
|
42
44
|
when Class
|
43
45
|
generate_class mod
|
@@ -356,12 +358,14 @@ module RBS
|
|
356
358
|
end
|
357
359
|
|
358
360
|
def generate_module(mod)
|
359
|
-
|
361
|
+
name = const_name(mod)
|
362
|
+
|
363
|
+
unless name
|
360
364
|
RBS.logger.warn("Skipping anonymous module #{mod}")
|
361
365
|
return
|
362
366
|
end
|
363
367
|
|
364
|
-
type_name = to_type_name(
|
368
|
+
type_name = to_type_name(name)
|
365
369
|
|
366
370
|
decl = AST::Declarations::Module.new(
|
367
371
|
name: type_name,
|
@@ -374,12 +378,13 @@ module RBS
|
|
374
378
|
)
|
375
379
|
|
376
380
|
each_mixin(mod.included_modules, *mod.included_modules.flat_map(&:included_modules), namespace: type_name.namespace) do |included_module|
|
377
|
-
|
381
|
+
included_module_name = const_name(included_module)
|
382
|
+
unless included_module_name
|
378
383
|
RBS.logger.warn("Skipping anonymous module #{included_module} included in #{mod}")
|
379
384
|
next
|
380
385
|
end
|
381
386
|
|
382
|
-
module_name = to_type_name(
|
387
|
+
module_name = to_type_name(included_module_name)
|
383
388
|
if module_name.namespace == type_name.namespace
|
384
389
|
module_name = TypeName.new(name: module_name.name, namespace: Namespace.empty)
|
385
390
|
end
|
@@ -399,6 +404,11 @@ module RBS
|
|
399
404
|
|
400
405
|
generate_constants mod
|
401
406
|
end
|
407
|
+
|
408
|
+
def const_name(const)
|
409
|
+
@module_name_method ||= Module.instance_method(:name)
|
410
|
+
@module_name_method.bind(const).call
|
411
|
+
end
|
402
412
|
end
|
403
413
|
end
|
404
414
|
end
|
data/lib/rbs/test/hook.rb
CHANGED
data/lib/rbs/test/tester.rb
CHANGED
@@ -56,7 +56,10 @@ module RBS
|
|
56
56
|
RBS.logger.info { "Skipping ##{name} because of `#{reason}`..." }
|
57
57
|
end
|
58
58
|
else
|
59
|
-
if
|
59
|
+
if !set.include?(name) && (
|
60
|
+
name == :initialize ||
|
61
|
+
klass.instance_methods(false).include?(name) ||
|
62
|
+
klass.private_instance_methods(false).include?(name))
|
60
63
|
RBS.logger.info { "Setting up method hook in ##{name}..." }
|
61
64
|
Hook.hook_instance_method klass, name, key: instance_key
|
62
65
|
set << name
|
data/lib/rbs/test/type_check.rb
CHANGED
@@ -202,11 +202,17 @@ module RBS
|
|
202
202
|
end
|
203
203
|
|
204
204
|
def get_class(type_name)
|
205
|
-
const_cache[type_name] ||=
|
205
|
+
const_cache[type_name] ||= begin
|
206
|
+
Object.const_get(type_name.to_s)
|
207
|
+
rescue NameError
|
208
|
+
nil
|
209
|
+
end
|
206
210
|
end
|
207
211
|
|
208
212
|
def is_double?(value)
|
209
213
|
unchecked_classes.any? { |unchecked_class| Test.call(value, IS_AP, Object.const_get(unchecked_class))}
|
214
|
+
rescue NameError
|
215
|
+
false
|
210
216
|
end
|
211
217
|
|
212
218
|
def value(val, type)
|
@@ -219,7 +225,7 @@ module RBS
|
|
219
225
|
when Types::Bases::Any
|
220
226
|
true
|
221
227
|
when Types::Bases::Bool
|
222
|
-
|
228
|
+
val.is_a?(TrueClass) || val.is_a?(FalseClass)
|
223
229
|
when Types::Bases::Top
|
224
230
|
true
|
225
231
|
when Types::Bases::Bottom
|
@@ -235,7 +241,7 @@ module RBS
|
|
235
241
|
when Types::Bases::Instance
|
236
242
|
Test.call(val, IS_AP, self_class)
|
237
243
|
when Types::ClassInstance
|
238
|
-
klass = get_class(type.name)
|
244
|
+
klass = get_class(type.name) or return false
|
239
245
|
case
|
240
246
|
when klass == ::Array
|
241
247
|
Test.call(val, IS_AP, klass) && each_sample(val).all? {|v| value(v, type.args[0]) }
|
@@ -281,7 +287,7 @@ module RBS
|
|
281
287
|
Test.call(val, IS_AP, klass)
|
282
288
|
end
|
283
289
|
when Types::ClassSingleton
|
284
|
-
klass = get_class(type.name)
|
290
|
+
klass = get_class(type.name) or return false
|
285
291
|
val == klass
|
286
292
|
when Types::Interface
|
287
293
|
methods = Set.new(Test.call(val, METHODS))
|
data/lib/rbs/version.rb
CHANGED
data/sig/constant_table.rbs
CHANGED
@@ -19,7 +19,7 @@ module RBS
|
|
19
19
|
|
20
20
|
def resolve_constant_reference_context: (Symbol, context: Array[Namespace]) -> Constant?
|
21
21
|
|
22
|
-
def resolve_constant_reference_inherit: (Symbol, scopes: Array[Namespace], ?no_object:
|
22
|
+
def resolve_constant_reference_inherit: (Symbol, scopes: Array[Namespace], ?no_object: boolish) -> Constant?
|
23
23
|
|
24
24
|
def constant_scopes: (TypeName) -> Array[Namespace]
|
25
25
|
|
data/sig/declarations.rbs
CHANGED
@@ -14,7 +14,7 @@ module RBS
|
|
14
14
|
attr_reader variance: variance
|
15
15
|
attr_reader skip_validation: bool
|
16
16
|
|
17
|
-
def initialize: (name: Symbol, variance: variance, skip_validation:
|
17
|
+
def initialize: (name: Symbol, variance: variance, skip_validation: boolish) -> void
|
18
18
|
|
19
19
|
include _ToJson
|
20
20
|
end
|
data/sig/definition.rbs
CHANGED
@@ -18,7 +18,7 @@ module RBS
|
|
18
18
|
class TypeDef
|
19
19
|
attr_reader type: MethodType
|
20
20
|
attr_reader member: method_member
|
21
|
-
attr_reader defined_in: TypeName
|
21
|
+
attr_reader defined_in: TypeName
|
22
22
|
attr_reader implemented_in: TypeName?
|
23
23
|
|
24
24
|
def initialize: (type: MethodType, member: method_member, defined_in: TypeName?, implemented_in: TypeName?) -> void
|
data/sig/environment_loader.rbs
CHANGED
@@ -42,12 +42,12 @@ module RBS
|
|
42
42
|
|
43
43
|
def gem?: (String, String?) -> Pathname?
|
44
44
|
|
45
|
-
def each_signature: (Pathname, ?immediate:
|
46
|
-
| (Pathname, ?immediate:
|
45
|
+
def each_signature: (Pathname, ?immediate: boolish) { (Pathname) -> void } -> void
|
46
|
+
| (Pathname, ?immediate: boolish) -> Enumerator[Pathname, void]
|
47
47
|
|
48
48
|
def each_library_path: { (path, Pathname) -> void } -> void
|
49
49
|
|
50
|
-
def no_builtin!: (?
|
50
|
+
def no_builtin!: (?boolish) -> self
|
51
51
|
|
52
52
|
def no_builtin?: () -> bool
|
53
53
|
|
data/sig/members.rbs
CHANGED
@@ -23,7 +23,7 @@ module RBS
|
|
23
23
|
attr_reader comment: Comment?
|
24
24
|
attr_reader overload: bool
|
25
25
|
|
26
|
-
def initialize: (name: Symbol, kind: kind, types: Array[MethodType], annotations: Array[Annotation], location: Location?, comment: Comment?, overload:
|
26
|
+
def initialize: (name: Symbol, kind: kind, types: Array[MethodType], annotations: Array[Annotation], location: Location?, comment: Comment?, overload: boolish) -> void
|
27
27
|
|
28
28
|
include _HashEqual
|
29
29
|
include _ToJson
|
@@ -34,7 +34,7 @@ module RBS
|
|
34
34
|
|
35
35
|
def overload?: () -> bool
|
36
36
|
|
37
|
-
def update: (?name: Symbol, ?kind: kind, ?types: Array[MethodType], ?annotations: Array[Annotation], ?location: Location?, ?comment: Comment?, ?overload:
|
37
|
+
def update: (?name: Symbol, ?kind: kind, ?types: Array[MethodType], ?annotations: Array[Annotation], ?location: Location?, ?comment: Comment?, ?overload: boolish) -> MethodDefinition
|
38
38
|
end
|
39
39
|
|
40
40
|
module Var
|
data/sig/method_types.rbs
CHANGED
data/sig/namespace.rbs
CHANGED
@@ -28,7 +28,7 @@ module RBS
|
|
28
28
|
class Namespace
|
29
29
|
attr_reader path: Array[Symbol]
|
30
30
|
|
31
|
-
def initialize: (path: Array[Symbol], absolute:
|
31
|
+
def initialize: (path: Array[Symbol], absolute: boolish) -> void
|
32
32
|
|
33
33
|
# Returns new _empty_ namespace.
|
34
34
|
def self.empty: () -> Namespace
|
data/stdlib/base64/base64.rbs
CHANGED
@@ -67,5 +67,5 @@ module Base64
|
|
67
67
|
# 64 Encoding with URL and Filename Safe Alphabet'' in RFC 4648. The alphabet
|
68
68
|
# uses '-' instead of '+' and '_' instead of '/'. Note that the result can still
|
69
69
|
# contain '='. You can remove the padding by setting `padding` as false.
|
70
|
-
def self?.urlsafe_encode64: (String bin, ?padding:
|
70
|
+
def self?.urlsafe_encode64: (String bin, ?padding: boolish) -> String
|
71
71
|
end
|
data/stdlib/builtin/array.rbs
CHANGED
@@ -234,7 +234,7 @@
|
|
234
234
|
# for pack.c
|
235
235
|
#
|
236
236
|
class Array[unchecked out Elem] < Object
|
237
|
-
include Enumerable[Elem,
|
237
|
+
include Enumerable[Elem, self]
|
238
238
|
|
239
239
|
# Returns a new array.
|
240
240
|
#
|
@@ -285,9 +285,9 @@ class Array[unchecked out Elem] < Object
|
|
285
285
|
# a # => [{"cat"=>"feline"}, {}]
|
286
286
|
#
|
287
287
|
def initialize: () -> void
|
288
|
-
| (Array[Elem] ary) -> void
|
288
|
+
| (::Array[Elem] ary) -> void
|
289
289
|
| (int size, ?Elem val) -> void
|
290
|
-
| (int size) { (Integer index) -> Elem } -> void
|
290
|
+
| (int size) { (::Integer index) -> Elem } -> void
|
291
291
|
|
292
292
|
# Returns a new array populated with the given objects.
|
293
293
|
#
|
@@ -324,7 +324,7 @@ class Array[unchecked out Elem] < Object
|
|
324
324
|
#
|
325
325
|
# See also Array#uniq.
|
326
326
|
#
|
327
|
-
def &: (Array[untyped] | _ToAry[untyped]) -> ::Array[Elem]
|
327
|
+
def &: (::Array[untyped] | _ToAry[untyped]) -> ::Array[Elem]
|
328
328
|
|
329
329
|
# Repetition --- With a String argument, equivalent to `ary.join(str)`.
|
330
330
|
#
|
@@ -334,8 +334,8 @@ class Array[unchecked out Elem] < Object
|
|
334
334
|
# [ 1, 2, 3 ] * 3 #=> [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
|
335
335
|
# [ 1, 2, 3 ] * "," #=> "1,2,3"
|
336
336
|
#
|
337
|
-
def *: (string str) -> String
|
338
|
-
| (int int) -> Array[Elem]
|
337
|
+
def *: (string str) -> ::String
|
338
|
+
| (int int) -> ::Array[Elem]
|
339
339
|
|
340
340
|
# Concatenation --- Returns a new array built by concatenating the two arrays
|
341
341
|
# together to produce a third array.
|
@@ -388,7 +388,7 @@ class Array[unchecked out Elem] < Object
|
|
388
388
|
# a
|
389
389
|
# #=> [ 1, 2, "c", "d", [ 3, 4 ] ]
|
390
390
|
#
|
391
|
-
def <<: (Elem) ->
|
391
|
+
def <<: (Elem) -> self
|
392
392
|
|
393
393
|
# Comparison --- Returns an integer (`-1`, `0`, or `+1`) if this array is less
|
394
394
|
# than, equal to, or greater than `other_ary`.
|
@@ -413,7 +413,7 @@ class Array[unchecked out Elem] < Object
|
|
413
413
|
# [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1
|
414
414
|
# [ 1, 2 ] <=> [ 1, :two ] #=> nil
|
415
415
|
#
|
416
|
-
def <=>: (untyped) -> Integer?
|
416
|
+
def <=>: (untyped) -> ::Integer?
|
417
417
|
|
418
418
|
# Equality --- Two arrays are equal if they contain the same number of elements
|
419
419
|
# and if each element is equal to (according to Object#==) the corresponding
|
@@ -452,7 +452,7 @@ class Array[unchecked out Elem] < Object
|
|
452
452
|
#
|
453
453
|
def []: (int index) -> Elem
|
454
454
|
| (int start, int length) -> ::Array[Elem]?
|
455
|
-
| (Range[Integer] range) -> ::Array[Elem]?
|
455
|
+
| (::Range[::Integer] range) -> ::Array[Elem]?
|
456
456
|
|
457
457
|
# Element Assignment --- Sets the element at `index`, or replaces a subarray
|
458
458
|
# from the `start` index for `length` elements, or replaces a subarray specified
|
@@ -484,17 +484,17 @@ class Array[unchecked out Elem] < Object
|
|
484
484
|
#
|
485
485
|
def []=: (int index, Elem obj) -> Elem
|
486
486
|
| (int start, int length, Elem obj) -> Elem
|
487
|
-
| (int start, int length, Array[Elem]) -> Array[Elem]
|
487
|
+
| (int start, int length, ::Array[Elem]) -> ::Array[Elem]
|
488
488
|
| (int start, int length, nil) -> nil
|
489
|
-
| (Range[Integer], Elem obj) -> Elem
|
490
|
-
| (Range[Integer], Array[Elem]) -> Array[Elem]
|
491
|
-
| (Range[Integer], nil) -> nil
|
489
|
+
| (::Range[::Integer], Elem obj) -> Elem
|
490
|
+
| (::Range[::Integer], ::Array[Elem]) -> ::Array[Elem]
|
491
|
+
| (::Range[::Integer], nil) -> nil
|
492
492
|
|
493
493
|
# See also Enumerable#all?
|
494
494
|
#
|
495
495
|
def all?: () -> bool
|
496
496
|
| (_Pattern[Elem] pattern) -> bool
|
497
|
-
| () { (Elem obj) ->
|
497
|
+
| () { (Elem obj) -> boolish } -> bool
|
498
498
|
|
499
499
|
# See also Enumerable#any?
|
500
500
|
#
|
@@ -517,7 +517,7 @@ class Array[unchecked out Elem] < Object
|
|
517
517
|
# a.assoc("letters") #=> [ "letters", "a", "b", "c" ]
|
518
518
|
# a.assoc("foo") #=> nil
|
519
519
|
#
|
520
|
-
def assoc: (untyped) -> Array[untyped]?
|
520
|
+
def assoc: (untyped) -> ::Array[untyped]?
|
521
521
|
|
522
522
|
# Returns the element at `index`. A negative index counts from the end of
|
523
523
|
# `self`. Returns `nil` if the index is out of range. See also Array#[].
|
@@ -577,7 +577,7 @@ class Array[unchecked out Elem] < Object
|
|
577
577
|
# actually picked up at each iteration.
|
578
578
|
#
|
579
579
|
def bsearch: () { (Elem) -> (true | false) } -> Elem?
|
580
|
-
| () { (Elem) -> Integer } -> Elem?
|
580
|
+
| () { (Elem) -> ::Integer } -> Elem?
|
581
581
|
|
582
582
|
# By using binary search, finds an index of a value from this array which meets
|
583
583
|
# the given condition in O(log n) where n is the size of the array.
|
@@ -587,8 +587,8 @@ class Array[unchecked out Elem] < Object
|
|
587
587
|
# that this method returns the index of the element instead of the element
|
588
588
|
# itself. For more details consult the documentation for #bsearch.
|
589
589
|
#
|
590
|
-
def bsearch_index: () { (Elem) -> (true | false) } -> Integer?
|
591
|
-
| () { (Elem) -> Integer } -> Integer?
|
590
|
+
def bsearch_index: () { (Elem) -> (true | false) } -> ::Integer?
|
591
|
+
| () { (Elem) -> ::Integer } -> ::Integer?
|
592
592
|
|
593
593
|
# Removes all elements from `self`.
|
594
594
|
#
|
@@ -610,8 +610,8 @@ class Array[unchecked out Elem] < Object
|
|
610
610
|
# a.map.with_index {|x, i| x * i} #=> ["", "b", "cc", "ddd"]
|
611
611
|
# a #=> ["a", "b", "c", "d"]
|
612
612
|
#
|
613
|
-
def collect: [U] () { (Elem item) -> U } -> Array[U]
|
614
|
-
| () -> Enumerator[Elem, Array[untyped]]
|
613
|
+
def collect: [U] () { (Elem item) -> U } -> ::Array[U]
|
614
|
+
| () -> ::Enumerator[Elem, ::Array[untyped]]
|
615
615
|
|
616
616
|
# Invokes the given block once for each element of `self`, replacing the element
|
617
617
|
# with the value returned by the block.
|
@@ -648,15 +648,15 @@ class Array[unchecked out Elem] < Object
|
|
648
648
|
# a.combination(0).to_a #=> [[]] # one combination of length 0
|
649
649
|
# a.combination(5).to_a #=> [] # no combinations of length 5
|
650
650
|
#
|
651
|
-
def combination: (int n) { (Array[Elem]) -> void } -> self
|
652
|
-
| (int n) -> Enumerator[Array[Elem], self]
|
651
|
+
def combination: (int n) { (::Array[Elem]) -> void } -> self
|
652
|
+
| (int n) -> ::Enumerator[::Array[Elem], self]
|
653
653
|
|
654
654
|
# Returns a copy of `self` with all `nil` elements removed.
|
655
655
|
#
|
656
656
|
# [ "a", nil, "b", nil, "c", nil ].compact
|
657
657
|
# #=> [ "a", "b", "c" ]
|
658
658
|
#
|
659
|
-
def compact: () -> Array[Elem]
|
659
|
+
def compact: () -> ::Array[Elem]
|
660
660
|
|
661
661
|
# Removes `nil` elements from the array.
|
662
662
|
#
|
@@ -665,7 +665,7 @@ class Array[unchecked out Elem] < Object
|
|
665
665
|
# [ "a", nil, "b", nil, "c" ].compact! #=> [ "a", "b", "c" ]
|
666
666
|
# [ "a", "b", "c" ].compact! #=> nil
|
667
667
|
#
|
668
|
-
def compact!: () ->
|
668
|
+
def compact!: () -> self?
|
669
669
|
|
670
670
|
# Appends the elements of `other_ary`s to `self`.
|
671
671
|
#
|
@@ -682,7 +682,7 @@ class Array[unchecked out Elem] < Object
|
|
682
682
|
#
|
683
683
|
# See also Array#+.
|
684
684
|
#
|
685
|
-
def concat: (
|
685
|
+
def concat: (*::Array[Elem] arrays) -> ::Array[Elem]
|
686
686
|
|
687
687
|
# Returns the number of elements.
|
688
688
|
#
|
@@ -697,9 +697,9 @@ class Array[unchecked out Elem] < Object
|
|
697
697
|
# ary.count(2) #=> 2
|
698
698
|
# ary.count {|x| x%2 == 0} #=> 3
|
699
699
|
#
|
700
|
-
def count: () -> Integer
|
701
|
-
| (untyped obj) -> Integer
|
702
|
-
| () { (Elem) ->
|
700
|
+
def count: () -> ::Integer
|
701
|
+
| (untyped obj) -> ::Integer
|
702
|
+
| () { (Elem) -> boolish } -> ::Integer
|
703
703
|
|
704
704
|
# Calls the given block for each element `n` times or forever if `nil` is given.
|
705
705
|
#
|
@@ -714,9 +714,9 @@ class Array[unchecked out Elem] < Object
|
|
714
714
|
# a.cycle(2) {|x| puts x} # print, a, b, c, a, b, c.
|
715
715
|
#
|
716
716
|
def cycle: (?int? n) { (Elem) -> void } -> nil
|
717
|
-
| (?int? n) -> Enumerator[Elem, nil]
|
717
|
+
| (?int? n) -> ::Enumerator[Elem, nil]
|
718
718
|
|
719
|
-
def deconstruct: () ->
|
719
|
+
def deconstruct: () -> self
|
720
720
|
|
721
721
|
# Deletes all items from `self` that are equal to `obj`.
|
722
722
|
#
|
@@ -759,8 +759,8 @@ class Array[unchecked out Elem] < Object
|
|
759
759
|
# scores = [ 97, 42, 75 ]
|
760
760
|
# scores.delete_if {|score| score < 80 } #=> [97]
|
761
761
|
#
|
762
|
-
def delete_if: () { (Elem item) ->
|
763
|
-
| () -> Enumerator[Elem, self]
|
762
|
+
def delete_if: () { (Elem item) -> boolish } -> self
|
763
|
+
| () -> ::Enumerator[Elem, self]
|
764
764
|
|
765
765
|
# Array Difference
|
766
766
|
#
|
@@ -786,7 +786,7 @@ class Array[unchecked out Elem] < Object
|
|
786
786
|
#
|
787
787
|
# See also Array#-.
|
788
788
|
#
|
789
|
-
def difference: (*::Array[untyped] arrays) -> Array[Elem]
|
789
|
+
def difference: (*::Array[untyped] arrays) -> ::Array[Elem]
|
790
790
|
|
791
791
|
# Extracts the nested value specified by the sequence of *idx* objects by
|
792
792
|
# calling `dig` at each step, returning `nil` if any intermediate step is `nil`.
|
@@ -824,8 +824,8 @@ class Array[unchecked out Elem] < Object
|
|
824
824
|
# a = [1, 2, 3, 4, 5, 0]
|
825
825
|
# a.drop_while {|i| i < 3 } #=> [3, 4, 5, 0]
|
826
826
|
#
|
827
|
-
def drop_while: () { (Elem obj) ->
|
828
|
-
| () -> ::Enumerator[Elem, Array[Elem]]
|
827
|
+
def drop_while: () { (Elem obj) -> boolish } -> ::Array[Elem]
|
828
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
829
829
|
|
830
830
|
# Calls the given block once for each element in `self`, passing that element as
|
831
831
|
# a parameter. Returns the array itself.
|
@@ -839,8 +839,8 @@ class Array[unchecked out Elem] < Object
|
|
839
839
|
#
|
840
840
|
# a -- b -- c --
|
841
841
|
#
|
842
|
-
def each: () -> ::Enumerator[Elem,
|
843
|
-
| () { (Elem item) -> void } ->
|
842
|
+
def each: () -> ::Enumerator[Elem, self]
|
843
|
+
| () { (Elem item) -> void } -> self
|
844
844
|
|
845
845
|
# Same as Array#each, but passes the `index` of the element instead of the
|
846
846
|
# element itself.
|
@@ -854,8 +854,8 @@ class Array[unchecked out Elem] < Object
|
|
854
854
|
#
|
855
855
|
# 0 -- 1 -- 2 --
|
856
856
|
#
|
857
|
-
def each_index: () { (Integer index) -> void } ->
|
858
|
-
| () -> ::Enumerator[Elem,
|
857
|
+
def each_index: () { (::Integer index) -> void } -> self
|
858
|
+
| () -> ::Enumerator[Elem, self]
|
859
859
|
|
860
860
|
# Returns `true` if `self` contains no elements.
|
861
861
|
#
|
@@ -887,7 +887,7 @@ class Array[unchecked out Elem] < Object
|
|
887
887
|
#
|
888
888
|
def fetch: (int index) -> Elem
|
889
889
|
| [T] (int index, T default) -> (Elem | T)
|
890
|
-
| [T] (
|
890
|
+
| [T] (int index) { (int index) -> T } -> (Elem | T)
|
891
891
|
|
892
892
|
# The first three forms set the selected elements of `self` (which may be the
|
893
893
|
# entire array) to `obj`.
|
@@ -911,9 +911,9 @@ class Array[unchecked out Elem] < Object
|
|
911
911
|
#
|
912
912
|
def fill: (Elem obj) -> self
|
913
913
|
| (Elem obj, int? start, ?int? length) -> self
|
914
|
-
| (Elem obj, Range[Integer] range) -> self
|
915
|
-
| (?int? start, ?int? length) { (Integer index) -> Elem } -> self
|
916
|
-
| (Range[Integer] range) { (Integer index) -> Elem } -> self
|
914
|
+
| (Elem obj, ::Range[::Integer] range) -> self
|
915
|
+
| (?int? start, ?int? length) { (::Integer index) -> Elem } -> self
|
916
|
+
| (::Range[::Integer] range) { (::Integer index) -> Elem } -> self
|
917
917
|
|
918
918
|
# Returns a new array containing all elements of `ary` for which the given
|
919
919
|
# `block` returns a true value.
|
@@ -929,8 +929,8 @@ class Array[unchecked out Elem] < Object
|
|
929
929
|
#
|
930
930
|
# Array#filter is an alias for Array#select.
|
931
931
|
#
|
932
|
-
def filter: () { (Elem item) ->
|
933
|
-
| () -> Enumerator[Elem, Array[Elem]]
|
932
|
+
def filter: () { (Elem item) -> boolish } -> ::Array[Elem]
|
933
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
934
934
|
|
935
935
|
# Invokes the given block passing in successive elements from `self`, deleting
|
936
936
|
# elements for which the block returns a `false` value.
|
@@ -945,8 +945,8 @@ class Array[unchecked out Elem] < Object
|
|
945
945
|
#
|
946
946
|
# Array#filter! is an alias for Array#select!.
|
947
947
|
#
|
948
|
-
def filter!: () { (Elem item) ->
|
949
|
-
| () -> Enumerator[Elem,
|
948
|
+
def filter!: () { (Elem item) -> boolish } -> self?
|
949
|
+
| () -> ::Enumerator[Elem, self?]
|
950
950
|
|
951
951
|
# Returns the *index* of the first object in `ary` such that the object is `==`
|
952
952
|
# to `obj`.
|
@@ -964,9 +964,9 @@ class Array[unchecked out Elem] < Object
|
|
964
964
|
# a.index("z") #=> nil
|
965
965
|
# a.index {|x| x == "b"} #=> 1
|
966
966
|
#
|
967
|
-
def find_index: (untyped obj) -> Integer?
|
968
|
-
| () { (Elem item) ->
|
969
|
-
| () -> Enumerator[Elem, Integer?]
|
967
|
+
def find_index: (untyped obj) -> ::Integer?
|
968
|
+
| () { (Elem item) -> boolish } -> ::Integer?
|
969
|
+
| () -> ::Enumerator[Elem, ::Integer?]
|
970
970
|
|
971
971
|
# Returns the first element, or the first `n` elements, of the array. If the
|
972
972
|
# array is empty, the first form returns `nil`, and the second form returns an
|
@@ -977,7 +977,7 @@ class Array[unchecked out Elem] < Object
|
|
977
977
|
# a.first(2) #=> ["q", "r"]
|
978
978
|
#
|
979
979
|
def first: () -> Elem?
|
980
|
-
| (int n) -> Array[Elem]
|
980
|
+
| (int n) -> ::Array[Elem]
|
981
981
|
|
982
982
|
# Returns a new array that is a one-dimensional flattening of `self`
|
983
983
|
# (recursively).
|
@@ -1010,7 +1010,7 @@ class Array[unchecked out Elem] < Object
|
|
1010
1010
|
# a = [ 1, 2, [3, [4, 5] ] ]
|
1011
1011
|
# a.flatten!(1) #=> [1, 2, 3, [4, 5]]
|
1012
1012
|
#
|
1013
|
-
def flatten!: (?int level) ->
|
1013
|
+
def flatten!: (?int level) -> self?
|
1014
1014
|
|
1015
1015
|
# Compute a hash-code for this array.
|
1016
1016
|
#
|
@@ -1019,7 +1019,7 @@ class Array[unchecked out Elem] < Object
|
|
1019
1019
|
#
|
1020
1020
|
# See also Object#hash.
|
1021
1021
|
#
|
1022
|
-
def hash: () -> Integer
|
1022
|
+
def hash: () -> ::Integer
|
1023
1023
|
|
1024
1024
|
# Returns `true` if the given `object` is present in `self` (that is, if any
|
1025
1025
|
# element `==` `object`), otherwise returns `false`.
|
@@ -1059,7 +1059,7 @@ class Array[unchecked out Elem] < Object
|
|
1059
1059
|
# a.insert(2, 99) #=> ["a", "b", 99, "c", "d"]
|
1060
1060
|
# a.insert(-2, 1, 2, 3) #=> ["a", "b", 99, "c", 1, 2, 3, "d"]
|
1061
1061
|
#
|
1062
|
-
def insert: (int index, *Elem obj) ->
|
1062
|
+
def insert: (int index, *Elem obj) -> self
|
1063
1063
|
|
1064
1064
|
# Creates a string representation of `self`, by calling #inspect on each
|
1065
1065
|
# element.
|
@@ -1079,7 +1079,7 @@ class Array[unchecked out Elem] < Object
|
|
1079
1079
|
#
|
1080
1080
|
# See also Array#&.
|
1081
1081
|
#
|
1082
|
-
def intersection: (
|
1082
|
+
def intersection: (*::Array[untyped] | _ToAry[untyped] other_ary) -> ::Array[Elem]
|
1083
1083
|
|
1084
1084
|
# Returns a string created by converting each element of the array to a string,
|
1085
1085
|
# separated by the given `separator`. If the `separator` is `nil`, it uses
|
@@ -1106,8 +1106,8 @@ class Array[unchecked out Elem] < Object
|
|
1106
1106
|
#
|
1107
1107
|
# See also Array#select!.
|
1108
1108
|
#
|
1109
|
-
def keep_if: () { (Elem item) ->
|
1110
|
-
| () -> Enumerator[Elem,
|
1109
|
+
def keep_if: () { (Elem item) -> boolish } -> self
|
1110
|
+
| () -> ::Enumerator[Elem, self]
|
1111
1111
|
|
1112
1112
|
# Returns the last element(s) of `self`. If the array is empty, the first form
|
1113
1113
|
# returns `nil`.
|
@@ -1119,14 +1119,14 @@ class Array[unchecked out Elem] < Object
|
|
1119
1119
|
# a.last(2) #=> ["y", "z"]
|
1120
1120
|
#
|
1121
1121
|
def last: () -> Elem?
|
1122
|
-
| (int n) -> Array[Elem]
|
1122
|
+
| (int n) -> ::Array[Elem]
|
1123
1123
|
|
1124
1124
|
# Returns the number of elements in `self`. May be zero.
|
1125
1125
|
#
|
1126
1126
|
# [ 1, 2, 3, 4, 5 ].length #=> 5
|
1127
1127
|
# [].length #=> 0
|
1128
1128
|
#
|
1129
|
-
def length: () -> Integer
|
1129
|
+
def length: () -> ::Integer
|
1130
1130
|
|
1131
1131
|
# Invokes the given block once for each element of `self`.
|
1132
1132
|
#
|
@@ -1172,9 +1172,9 @@ class Array[unchecked out Elem] < Object
|
|
1172
1172
|
# ary.max(2) {|a, b| a.length <=> b.length } #=> ["albatross", "horse"]
|
1173
1173
|
#
|
1174
1174
|
def max: () -> Elem?
|
1175
|
-
| () { (Elem a, Elem b) -> Integer? } -> Elem?
|
1176
|
-
| (int n) -> Array[Elem]
|
1177
|
-
| (int n) { (Elem a, Elem b) -> Integer? } -> Array[Elem]
|
1175
|
+
| () { (Elem a, Elem b) -> ::Integer? } -> Elem?
|
1176
|
+
| (int n) -> ::Array[Elem]
|
1177
|
+
| (int n) { (Elem a, Elem b) -> ::Integer? } -> ::Array[Elem]
|
1178
1178
|
|
1179
1179
|
# Returns the object in *ary* with the minimum value. The first form assumes all
|
1180
1180
|
# objects implement Comparable; the second uses the block to return *a <=> b*.
|
@@ -1198,7 +1198,7 @@ class Array[unchecked out Elem] < Object
|
|
1198
1198
|
# <=> b`.
|
1199
1199
|
#
|
1200
1200
|
def minmax: () -> [ Elem?, Elem? ]
|
1201
|
-
| () { (Elem a, Elem b) -> Integer? } -> [ Elem?, Elem? ]
|
1201
|
+
| () { (Elem a, Elem b) -> ::Integer? } -> [ Elem?, Elem? ]
|
1202
1202
|
|
1203
1203
|
# See also Enumerable#none?
|
1204
1204
|
#
|
@@ -1352,8 +1352,8 @@ class Array[unchecked out Elem] < Object
|
|
1352
1352
|
# a.permutation(0).to_a #=> [[]] # one permutation of length 0
|
1353
1353
|
# a.permutation(4).to_a #=> [] # no permutations of length 4
|
1354
1354
|
#
|
1355
|
-
def permutation: (?
|
1356
|
-
| (?
|
1355
|
+
def permutation: (?int n) -> ::Enumerator[::Array[Elem], ::Array[Elem]]
|
1356
|
+
| (?int n) { (::Array[Elem] p) -> void } -> ::Array[Elem]
|
1357
1357
|
|
1358
1358
|
# Removes the last element from `self` and returns it, or `nil` if the array is
|
1359
1359
|
# empty.
|
@@ -1368,7 +1368,7 @@ class Array[unchecked out Elem] < Object
|
|
1368
1368
|
# a #=> ["a"]
|
1369
1369
|
#
|
1370
1370
|
def pop: () -> Elem?
|
1371
|
-
| (int n) -> Array[Elem]
|
1371
|
+
| (int n) -> ::Array[Elem]
|
1372
1372
|
|
1373
1373
|
alias prepend unshift
|
1374
1374
|
|
@@ -1387,10 +1387,10 @@ class Array[unchecked out Elem] < Object
|
|
1387
1387
|
# [1,2].product() #=> [[1],[2]]
|
1388
1388
|
# [1,2].product([]) #=> []
|
1389
1389
|
#
|
1390
|
-
def product: () -> Array[[Elem]]
|
1391
|
-
| [X] (Array[X] other_ary) -> Array[[Elem, X]]
|
1392
|
-
| [X, Y] (Array[X] other_ary1, Array[Y] other_ary2) -> Array[[Elem, X, Y]]
|
1393
|
-
| [U] (*::Array[U] other_arys) -> Array[Array[Elem | U]]
|
1390
|
+
def product: () -> ::Array[[Elem]]
|
1391
|
+
| [X] (::Array[X] other_ary) -> ::Array[[Elem, X]]
|
1392
|
+
| [X, Y] (::Array[X] other_ary1, ::Array[Y] other_ary2) -> ::Array[[Elem, X, Y]]
|
1393
|
+
| [U] (*::Array[U] other_arys) -> ::Array[::Array[Elem | U]]
|
1394
1394
|
|
1395
1395
|
# Append --- Pushes the given object(s) on to the end of this array. This
|
1396
1396
|
# expression returns the array itself, so several appends may be chained
|
@@ -1402,7 +1402,7 @@ class Array[unchecked out Elem] < Object
|
|
1402
1402
|
# [1, 2, 3].push(4).push(5)
|
1403
1403
|
# #=> [1, 2, 3, 4, 5]
|
1404
1404
|
#
|
1405
|
-
def push: (*Elem obj) ->
|
1405
|
+
def push: (*Elem obj) -> self
|
1406
1406
|
|
1407
1407
|
# Searches through the array whose elements are also arrays.
|
1408
1408
|
#
|
@@ -1436,8 +1436,8 @@ class Array[unchecked out Elem] < Object
|
|
1436
1436
|
#
|
1437
1437
|
# If no block is given, an Enumerator is returned instead.
|
1438
1438
|
#
|
1439
|
-
def reject!: () { (Elem item) ->
|
1440
|
-
| () -> ::Enumerator[Elem,
|
1439
|
+
def reject!: () { (Elem item) -> boolish } -> self?
|
1440
|
+
| () -> ::Enumerator[Elem, self?]
|
1441
1441
|
|
1442
1442
|
# When invoked with a block, yields all repeated combinations of length `n` of
|
1443
1443
|
# elements from the array and then returns the array itself.
|
@@ -1459,8 +1459,8 @@ class Array[unchecked out Elem] < Object
|
|
1459
1459
|
# # [2,2,2,2],[2,2,2,3],[2,2,3,3],[2,3,3,3],[3,3,3,3]]
|
1460
1460
|
# a.repeated_combination(0).to_a #=> [[]] # one combination of length 0
|
1461
1461
|
#
|
1462
|
-
def repeated_combination: (int n) { (Array[Elem] c) -> void } -> self
|
1463
|
-
| (int n) -> Enumerator[Array[Elem], self]
|
1462
|
+
def repeated_combination: (int n) { (::Array[Elem] c) -> void } -> self
|
1463
|
+
| (int n) -> ::Enumerator[::Array[Elem], self]
|
1464
1464
|
|
1465
1465
|
# When invoked with a block, yield all repeated permutations of length `n` of
|
1466
1466
|
# the elements of the array, then return the array itself.
|
@@ -1479,8 +1479,8 @@ class Array[unchecked out Elem] < Object
|
|
1479
1479
|
# # [2,1,1],[2,1,2],[2,2,1],[2,2,2]]
|
1480
1480
|
# a.repeated_permutation(0).to_a #=> [[]] # one permutation of length 0
|
1481
1481
|
#
|
1482
|
-
def repeated_permutation: (int n) { (Array[Elem] p) -> void } -> self
|
1483
|
-
| (int n) -> Enumerator[Array[Elem], self]
|
1482
|
+
def repeated_permutation: (int n) { (::Array[Elem] p) -> void } -> self
|
1483
|
+
| (int n) -> ::Enumerator[::Array[Elem], self]
|
1484
1484
|
|
1485
1485
|
# Replaces the contents of `self` with the contents of `other_ary`, truncating
|
1486
1486
|
# or expanding if necessary.
|
@@ -1489,14 +1489,14 @@ class Array[unchecked out Elem] < Object
|
|
1489
1489
|
# a.replace([ "x", "y", "z" ]) #=> ["x", "y", "z"]
|
1490
1490
|
# a #=> ["x", "y", "z"]
|
1491
1491
|
#
|
1492
|
-
def replace: (Array[Elem]) -> self
|
1492
|
+
def replace: (::Array[Elem]) -> self
|
1493
1493
|
|
1494
1494
|
# Returns a new array containing `self`'s elements in reverse order.
|
1495
1495
|
#
|
1496
1496
|
# [ "a", "b", "c" ].reverse #=> ["c", "b", "a"]
|
1497
1497
|
# [ 1 ].reverse #=> [1]
|
1498
1498
|
#
|
1499
|
-
def reverse: () -> Array[Elem]
|
1499
|
+
def reverse: () -> ::Array[Elem]
|
1500
1500
|
|
1501
1501
|
# Reverses `self` in place.
|
1502
1502
|
#
|
@@ -1504,7 +1504,7 @@ class Array[unchecked out Elem] < Object
|
|
1504
1504
|
# a.reverse! #=> ["c", "b", "a"]
|
1505
1505
|
# a #=> ["c", "b", "a"]
|
1506
1506
|
#
|
1507
|
-
def reverse!: () -> Array[Elem]
|
1507
|
+
def reverse!: () -> ::Array[Elem]
|
1508
1508
|
|
1509
1509
|
# Same as Array#each, but traverses `self` in reverse order.
|
1510
1510
|
#
|
@@ -1515,8 +1515,8 @@ class Array[unchecked out Elem] < Object
|
|
1515
1515
|
#
|
1516
1516
|
# c b a
|
1517
1517
|
#
|
1518
|
-
def reverse_each: () { (Elem item) -> void } ->
|
1519
|
-
| () -> Enumerator[Elem,
|
1518
|
+
def reverse_each: () { (Elem item) -> void } -> self
|
1519
|
+
| () -> ::Enumerator[Elem, self]
|
1520
1520
|
|
1521
1521
|
# Returns the *index* of the last object in `self` `==` to `obj`.
|
1522
1522
|
#
|
@@ -1534,9 +1534,9 @@ class Array[unchecked out Elem] < Object
|
|
1534
1534
|
# a.rindex("z") #=> nil
|
1535
1535
|
# a.rindex {|x| x == "b"} #=> 3
|
1536
1536
|
#
|
1537
|
-
def rindex: (untyped obj) -> Integer?
|
1538
|
-
| () { (Elem item) ->
|
1539
|
-
| () -> Enumerator[Elem, Integer?]
|
1537
|
+
def rindex: (untyped obj) -> ::Integer?
|
1538
|
+
| () { (Elem item) -> boolish } -> ::Integer?
|
1539
|
+
| () -> ::Enumerator[Elem, ::Integer?]
|
1540
1540
|
|
1541
1541
|
# Returns a new array by rotating `self` so that the element at `count` is the
|
1542
1542
|
# first element of the new array.
|
@@ -1550,7 +1550,7 @@ class Array[unchecked out Elem] < Object
|
|
1550
1550
|
# a.rotate(2) #=> ["c", "d", "a", "b"]
|
1551
1551
|
# a.rotate(-3) #=> ["b", "c", "d", "a"]
|
1552
1552
|
#
|
1553
|
-
def rotate: (?int count) -> Array[Elem]
|
1553
|
+
def rotate: (?int count) -> ::Array[Elem]
|
1554
1554
|
|
1555
1555
|
# Rotates `self` in place so that the element at `count` comes first, and
|
1556
1556
|
# returns `self`.
|
@@ -1564,7 +1564,7 @@ class Array[unchecked out Elem] < Object
|
|
1564
1564
|
# a.rotate!(2) #=> ["d", "a", "b", "c"]
|
1565
1565
|
# a.rotate!(-3) #=> ["a", "b", "c", "d"]
|
1566
1566
|
#
|
1567
|
-
def rotate!: (?int count) ->
|
1567
|
+
def rotate!: (?int count) -> self
|
1568
1568
|
|
1569
1569
|
# Choose a random element or `n` random elements from the array.
|
1570
1570
|
#
|
@@ -1601,8 +1601,8 @@ class Array[unchecked out Elem] < Object
|
|
1601
1601
|
#
|
1602
1602
|
# Array#filter is an alias for Array#select.
|
1603
1603
|
#
|
1604
|
-
def select: () { (Elem item) ->
|
1605
|
-
| () -> Enumerator[Elem, Array[Elem]]
|
1604
|
+
def select: () { (Elem item) -> boolish } -> ::Array[Elem]
|
1605
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
1606
1606
|
|
1607
1607
|
# Invokes the given block passing in successive elements from `self`, deleting
|
1608
1608
|
# elements for which the block returns a `false` value.
|
@@ -1617,8 +1617,8 @@ class Array[unchecked out Elem] < Object
|
|
1617
1617
|
#
|
1618
1618
|
# Array#filter! is an alias for Array#select!.
|
1619
1619
|
#
|
1620
|
-
def select!: () { (Elem item) ->
|
1621
|
-
| () -> ::Enumerator[Elem,
|
1620
|
+
def select!: () { (Elem item) -> boolish } -> self?
|
1621
|
+
| () -> ::Enumerator[Elem, self?]
|
1622
1622
|
|
1623
1623
|
# Removes the first element of `self` and returns it (shifting all other
|
1624
1624
|
# elements down by one). Returns `nil` if the array is empty.
|
@@ -1637,7 +1637,7 @@ class Array[unchecked out Elem] < Object
|
|
1637
1637
|
# args #=> ["filename"]
|
1638
1638
|
#
|
1639
1639
|
def shift: () -> Elem?
|
1640
|
-
| (?int n) -> Array[Elem]
|
1640
|
+
| (?int n) -> ::Array[Elem]
|
1641
1641
|
|
1642
1642
|
# Returns a new array with elements of `self` shuffled.
|
1643
1643
|
#
|
@@ -1649,7 +1649,7 @@ class Array[unchecked out Elem] < Object
|
|
1649
1649
|
#
|
1650
1650
|
# a.shuffle(random: Random.new(1)) #=> [1, 3, 2]
|
1651
1651
|
#
|
1652
|
-
def shuffle: (?random: Random rng) -> Array[Elem]
|
1652
|
+
def shuffle: (?random: Random rng) -> ::Array[Elem]
|
1653
1653
|
|
1654
1654
|
# Shuffles elements in `self` in place.
|
1655
1655
|
#
|
@@ -1661,7 +1661,7 @@ class Array[unchecked out Elem] < Object
|
|
1661
1661
|
#
|
1662
1662
|
# a.shuffle!(random: Random.new(1)) #=> [1, 3, 2]
|
1663
1663
|
#
|
1664
|
-
def shuffle!: (?random: Random rng) ->
|
1664
|
+
def shuffle!: (?random: Random rng) -> self
|
1665
1665
|
|
1666
1666
|
alias size length
|
1667
1667
|
|
@@ -1691,8 +1691,8 @@ class Array[unchecked out Elem] < Object
|
|
1691
1691
|
# a[5..10] #=> []
|
1692
1692
|
#
|
1693
1693
|
def slice: (int index) -> Elem?
|
1694
|
-
| (int start, int length) -> Array[Elem]?
|
1695
|
-
| (Range[Integer] range) -> Array[Elem]?
|
1694
|
+
| (int start, int length) -> ::Array[Elem]?
|
1695
|
+
| (::Range[::Integer] range) -> ::Array[Elem]?
|
1696
1696
|
|
1697
1697
|
# Deletes the element(s) given by an `index` (optionally up to `length`
|
1698
1698
|
# elements) or by a `range`.
|
@@ -1709,8 +1709,8 @@ class Array[unchecked out Elem] < Object
|
|
1709
1709
|
# a #=> ["a"]
|
1710
1710
|
#
|
1711
1711
|
def slice!: (int index) -> Elem?
|
1712
|
-
| (int start, int length) -> Array[Elem]?
|
1713
|
-
| (Range[Integer] range) -> Array[Elem]?
|
1712
|
+
| (int start, int length) -> ::Array[Elem]?
|
1713
|
+
| (::Range[::Integer] range) -> ::Array[Elem]?
|
1714
1714
|
|
1715
1715
|
# Returns a new array created by sorting `self`.
|
1716
1716
|
#
|
@@ -1736,7 +1736,7 @@ class Array[unchecked out Elem] < Object
|
|
1736
1736
|
# See also Enumerable#sort_by.
|
1737
1737
|
#
|
1738
1738
|
def sort: () -> ::Array[Elem]
|
1739
|
-
| () { (Elem a, Elem b) -> Integer? } -> Array[Elem]
|
1739
|
+
| () { (Elem a, Elem b) -> ::Integer? } -> ::Array[Elem]
|
1740
1740
|
|
1741
1741
|
# Sorts `self` in place.
|
1742
1742
|
#
|
@@ -1756,8 +1756,8 @@ class Array[unchecked out Elem] < Object
|
|
1756
1756
|
#
|
1757
1757
|
# See also Enumerable#sort_by.
|
1758
1758
|
#
|
1759
|
-
def sort!: () ->
|
1760
|
-
| () { (Elem a, Elem b) -> Integer? } ->
|
1759
|
+
def sort!: () -> self
|
1760
|
+
| () { (Elem a, Elem b) -> ::Integer? } -> self
|
1761
1761
|
|
1762
1762
|
# Sorts `self` in place using a set of keys generated by mapping the values in
|
1763
1763
|
# `self` through the given block.
|
@@ -1769,8 +1769,8 @@ class Array[unchecked out Elem] < Object
|
|
1769
1769
|
#
|
1770
1770
|
# See also Enumerable#sort_by.
|
1771
1771
|
#
|
1772
|
-
def sort_by!: [U] () { (Elem obj) -> U } -> Array[Elem]
|
1773
|
-
| () -> Enumerator[Elem, Array[Elem]]
|
1772
|
+
def sort_by!: [U] () { (Elem obj) -> U } -> ::Array[Elem]
|
1773
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
1774
1774
|
|
1775
1775
|
# Returns the sum of elements. For example, [e1, e2, e3].sum returns init + e1 +
|
1776
1776
|
# e2 + e3.
|
@@ -1828,14 +1828,14 @@ class Array[unchecked out Elem] < Object
|
|
1828
1828
|
# a = [1, 2, 3, 4, 5, 0]
|
1829
1829
|
# a.take_while {|i| i < 3} #=> [1, 2]
|
1830
1830
|
#
|
1831
|
-
def take_while: () { (Elem obj) ->
|
1832
|
-
| () -> Enumerator[Elem, Array[Elem]]
|
1831
|
+
def take_while: () { (Elem obj) -> boolish } -> ::Array[Elem]
|
1832
|
+
| () -> ::Enumerator[Elem, ::Array[Elem]]
|
1833
1833
|
|
1834
1834
|
# Returns `self`.
|
1835
1835
|
#
|
1836
1836
|
# If called on a subclass of Array, converts the receiver to an Array object.
|
1837
1837
|
#
|
1838
|
-
def to_a: () -> Array[Elem]
|
1838
|
+
def to_a: () -> ::Array[Elem]
|
1839
1839
|
|
1840
1840
|
# Returns `self`.
|
1841
1841
|
#
|
@@ -1864,7 +1864,7 @@ class Array[unchecked out Elem] < Object
|
|
1864
1864
|
#
|
1865
1865
|
# If the length of the subarrays don't match, an IndexError is raised.
|
1866
1866
|
#
|
1867
|
-
def transpose: () -> Array[Array[untyped]]
|
1867
|
+
def transpose: () -> ::Array[::Array[untyped]]
|
1868
1868
|
|
1869
1869
|
# Set Union --- Returns a new array by joining `other_ary`s with `self`,
|
1870
1870
|
# excluding any duplicates and preserving the order from the given arrays.
|
@@ -1877,7 +1877,7 @@ class Array[unchecked out Elem] < Object
|
|
1877
1877
|
#
|
1878
1878
|
# See also Array#|.
|
1879
1879
|
#
|
1880
|
-
def union: [T] (
|
1880
|
+
def union: [T] (*::Array[T] other_arys) -> ::Array[T | Elem]
|
1881
1881
|
|
1882
1882
|
# Returns a new array by removing duplicate values in `self`.
|
1883
1883
|
#
|
@@ -1893,8 +1893,8 @@ class Array[unchecked out Elem] < Object
|
|
1893
1893
|
# b = [["student","sam"], ["student","george"], ["teacher","matz"]]
|
1894
1894
|
# b.uniq {|s| s.first} # => [["student", "sam"], ["teacher", "matz"]]
|
1895
1895
|
#
|
1896
|
-
def uniq: () -> Array[Elem]
|
1897
|
-
| () { (Elem item) -> untyped } -> Array[Elem]
|
1896
|
+
def uniq: () -> ::Array[Elem]
|
1897
|
+
| () { (Elem item) -> untyped } -> ::Array[Elem]
|
1898
1898
|
|
1899
1899
|
# Removes duplicate elements from `self`.
|
1900
1900
|
#
|
@@ -1915,8 +1915,8 @@ class Array[unchecked out Elem] < Object
|
|
1915
1915
|
# c = [["student","sam"], ["student","george"], ["teacher","matz"]]
|
1916
1916
|
# c.uniq! {|s| s.first} # => [["student", "sam"], ["teacher", "matz"]]
|
1917
1917
|
#
|
1918
|
-
def uniq!: () ->
|
1919
|
-
| () { (Elem) -> untyped } ->
|
1918
|
+
def uniq!: () -> self?
|
1919
|
+
| () { (Elem) -> untyped } -> self?
|
1920
1920
|
|
1921
1921
|
# Prepends objects to the front of `self`, moving other elements upwards. See
|
1922
1922
|
# also Array#shift for the opposite effect.
|
@@ -1925,7 +1925,7 @@ class Array[unchecked out Elem] < Object
|
|
1925
1925
|
# a.unshift("a") #=> ["a", "b", "c", "d"]
|
1926
1926
|
# a.unshift(1, 2) #=> [ 1, 2, "a", "b", "c", "d"]
|
1927
1927
|
#
|
1928
|
-
def unshift: (*Elem obj) ->
|
1928
|
+
def unshift: (*Elem obj) -> self
|
1929
1929
|
|
1930
1930
|
# Returns an array containing the elements in `self` corresponding to the given
|
1931
1931
|
# `selector`(s).
|
@@ -1940,7 +1940,7 @@ class Array[unchecked out Elem] < Object
|
|
1940
1940
|
# a.values_at(-1, -2, -2, -7) # => ["f", "e", "e", nil]
|
1941
1941
|
# a.values_at(4..6, 3...6) # => ["e", "f", nil, "d", "e", "f"]
|
1942
1942
|
#
|
1943
|
-
def values_at: (*int | Range[Integer] selector) -> Array[Elem?]
|
1943
|
+
def values_at: (*int | ::Range[::Integer] selector) -> ::Array[Elem?]
|
1944
1944
|
|
1945
1945
|
# Converts any arguments to arrays, then merges elements of `self` with
|
1946
1946
|
# corresponding elements from each argument.
|
@@ -1960,10 +1960,10 @@ class Array[unchecked out Elem] < Object
|
|
1960
1960
|
# [1, 2].zip(a, b) #=> [[1, 4, 7], [2, 5, 8]]
|
1961
1961
|
# a.zip([1, 2], [8]) #=> [[4, 1, 8], [5, 2, nil], [6, nil, nil]]
|
1962
1962
|
#
|
1963
|
-
def zip: [U] (Array[U] arg) -> Array[[ Elem, U? ]]
|
1964
|
-
| (Array[untyped] arg,
|
1965
|
-
| [U] (Array[U] arg) { ([Elem, U?]) -> void } -> void
|
1966
|
-
| (Array[untyped] arg,
|
1963
|
+
def zip: [U] (::Array[U] arg) -> ::Array[[ Elem, U? ]]
|
1964
|
+
| (::Array[untyped] arg, *::Array[untyped] args) -> ::Array[::Array[untyped]]
|
1965
|
+
| [U] (::Array[U] arg) { ([Elem, U?]) -> void } -> void
|
1966
|
+
| (::Array[untyped] arg, *::Array[untyped] args) { (::Array[untyped]) -> void } -> void
|
1967
1967
|
|
1968
1968
|
# Set Union --- Returns a new array by joining `ary` with `other_ary`, excluding
|
1969
1969
|
# any duplicates and preserving the order from the given arrays.
|
@@ -1975,7 +1975,7 @@ class Array[unchecked out Elem] < Object
|
|
1975
1975
|
#
|
1976
1976
|
# See also Array#union.
|
1977
1977
|
#
|
1978
|
-
def |: [T] (Array[T] other_ary) -> Array[Elem | T]
|
1978
|
+
def |: [T] (::Array[T] other_ary) -> ::Array[Elem | T]
|
1979
1979
|
|
1980
1980
|
private
|
1981
1981
|
|
@@ -1989,8 +1989,12 @@ class Array[unchecked out Elem] < Object
|
|
1989
1989
|
def initialize_copy: (self other_ary) -> void
|
1990
1990
|
end
|
1991
1991
|
|
1992
|
+
interface _ToA[T]
|
1993
|
+
def to_a: () -> Array[T]
|
1994
|
+
end
|
1995
|
+
|
1992
1996
|
interface _ToAry[T]
|
1993
|
-
def to_ary: () -> Array[T]
|
1997
|
+
def to_ary: () -> ::Array[T]
|
1994
1998
|
end
|
1995
1999
|
|
1996
2000
|
interface Array::_Pattern[T]
|