rbs 0.13.1 → 0.14.0
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/ruby.yml +1 -1
- data/.gitignore +0 -1
- data/CHANGELOG.md +7 -2
- data/Gemfile +3 -0
- data/README.md +8 -2
- data/Steepfile +1 -0
- data/bin/annotate-with-rdoc +1 -1
- data/bin/setup +0 -2
- data/docs/CONTRIBUTING.md +1 -0
- data/goodcheck.yml +22 -5
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/definition_builder.rb +4 -5
- data/lib/rbs/environment.rb +1 -1
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/parser.rb +3146 -0
- data/lib/rbs/parser.y +7 -2
- data/lib/rbs/test/setup_helper.rb +4 -4
- data/lib/rbs/test/type_check.rb +2 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/variance_calculator.rb +1 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +1 -1
- data/sig/constant.rbs +2 -2
- data/sig/constant_table.rbs +10 -10
- data/sig/declarations.rbs +1 -1
- data/sig/definition.rbs +1 -1
- data/sig/namespace.rbs +3 -3
- data/sig/parser.rbs +25 -0
- data/sig/substitution.rbs +3 -3
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +1 -1
- data/sig/writer.rbs +15 -15
- data/stdlib/benchmark/benchmark.rbs +2 -2
- data/stdlib/builtin/basic_object.rbs +54 -54
- data/stdlib/builtin/binding.rbs +42 -42
- data/stdlib/builtin/class.rbs +33 -33
- data/stdlib/builtin/complex.rbs +90 -90
- data/stdlib/builtin/encoding.rbs +33 -33
- data/stdlib/builtin/enumerable.rbs +32 -32
- data/stdlib/builtin/enumerator.rbs +35 -35
- data/stdlib/builtin/errors.rbs +1 -1
- data/stdlib/builtin/exception.rbs +50 -50
- data/stdlib/builtin/false_class.rbs +6 -6
- data/stdlib/builtin/fiber.rbs +14 -14
- data/stdlib/builtin/fiber_error.rbs +1 -1
- data/stdlib/builtin/float.rbs +161 -161
- data/stdlib/builtin/gc.rbs +1 -1
- data/stdlib/builtin/io.rbs +83 -83
- data/stdlib/builtin/kernel.rbs +69 -69
- data/stdlib/builtin/match_data.rbs +1 -1
- data/stdlib/builtin/method.rbs +19 -19
- data/stdlib/builtin/nil_class.rbs +20 -20
- data/stdlib/builtin/numeric.rbs +101 -101
- data/stdlib/builtin/object.rbs +172 -172
- data/stdlib/builtin/proc.rbs +91 -91
- data/stdlib/builtin/range.rbs +2 -4
- data/stdlib/builtin/rational.rbs +83 -83
- data/stdlib/builtin/signal.rbs +7 -7
- data/stdlib/builtin/string.rbs +4 -4
- data/stdlib/builtin/string_io.rbs +1 -1
- data/stdlib/builtin/thread.rbs +185 -185
- data/stdlib/builtin/thread_group.rbs +2 -2
- data/stdlib/builtin/true_class.rbs +9 -9
- data/stdlib/builtin/warning.rbs +1 -1
- data/stdlib/date/date.rbs +2 -2
- data/stdlib/find/find.rbs +10 -10
- data/stdlib/pathname/pathname.rbs +1 -1
- data/stdlib/tmpdir/tmpdir.rbs +12 -12
- metadata +3 -2
data/stdlib/builtin/kernel.rbs
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# The [Kernel](Kernel) module is included by class
|
2
2
|
# [Object](https://ruby-doc.org/core-2.6.3/Object.html), so its methods
|
3
3
|
# are available in every Ruby object.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# The [Kernel](Kernel) instance methods are documented
|
6
6
|
# in class [Object](https://ruby-doc.org/core-2.6.3/Object.html) while the
|
7
7
|
# module methods are documented here. These methods are called without a
|
8
8
|
# receiver and thus can be called in functional form:
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# ```ruby
|
11
11
|
# sprintf "%.1f", 1.234 #=> "1.2"
|
12
12
|
# ```
|
13
13
|
module Kernel
|
14
14
|
private
|
15
|
-
|
15
|
+
|
16
16
|
def caller: (?Integer start_or_range, ?Integer length) -> ::Array[String]?
|
17
17
|
| (?::Range[Integer] start_or_range) -> ::Array[String]?
|
18
18
|
| () -> ::Array[String]
|
@@ -24,13 +24,13 @@ module Kernel
|
|
24
24
|
| () { (Object tag) -> untyped } -> untyped
|
25
25
|
|
26
26
|
# In a perfect world this should be:
|
27
|
-
#
|
27
|
+
#
|
28
28
|
# returns(T.class_of(T.self_type))
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# but that doesn't work (yet). Even making it:
|
31
|
-
#
|
31
|
+
#
|
32
32
|
# returns(Class)
|
33
|
-
#
|
33
|
+
#
|
34
34
|
# is very surprising since users expect their methods to be present.
|
35
35
|
# So we settle for untyped.
|
36
36
|
def `class`: () -> untyped
|
@@ -42,7 +42,7 @@ module Kernel
|
|
42
42
|
|
43
43
|
# Returns `true` if `yield` would execute a block in the current context.
|
44
44
|
# The `iterator?` form is mildly deprecated.
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# ```ruby
|
47
47
|
# def try
|
48
48
|
# if block_given?
|
@@ -59,7 +59,7 @@ module Kernel
|
|
59
59
|
alias block_given? iterator?
|
60
60
|
|
61
61
|
# Returns the names of the current local variables.
|
62
|
-
#
|
62
|
+
#
|
63
63
|
# ```ruby
|
64
64
|
# fred = 1
|
65
65
|
# for i in 1..10
|
@@ -102,12 +102,12 @@ module Kernel
|
|
102
102
|
# collect the termination statuses of its children or use `Process.detach`
|
103
103
|
# to register disinterest in their status; otherwise, the operating system
|
104
104
|
# may accumulate zombie processes.
|
105
|
-
#
|
105
|
+
#
|
106
106
|
# The thread calling fork is the only thread in the created child process.
|
107
107
|
# fork doesn’t copy other threads.
|
108
|
-
#
|
108
|
+
#
|
109
109
|
# If fork is not usable, Process.respond\_to?(:fork) returns false.
|
110
|
-
#
|
110
|
+
#
|
111
111
|
# Note that fork(2) is not available on some platforms like Windows and
|
112
112
|
# NetBSD 4. Therefore you should use spawn() instead of fork().
|
113
113
|
def fork: () -> Integer?
|
@@ -179,16 +179,16 @@ module Kernel
|
|
179
179
|
|
180
180
|
# Returns `arg` as an [Array](https://ruby-doc.org/core-2.6.3/Array.html)
|
181
181
|
# .
|
182
|
-
#
|
182
|
+
#
|
183
183
|
# First tries to call `to_ary` on `arg`, then `to_a` . If `arg` does not
|
184
184
|
# respond to `to_ary` or `to_a`, returns an
|
185
185
|
# [Array](https://ruby-doc.org/core-2.6.3/Array.html) of length 1
|
186
186
|
# containing `arg` .
|
187
|
-
#
|
187
|
+
#
|
188
188
|
# If `to_ary` or `to_a` returns something other than an
|
189
189
|
# [Array](https://ruby-doc.org/core-2.6.3/Array.html), raises a
|
190
190
|
# `TypeError` .
|
191
|
-
#
|
191
|
+
#
|
192
192
|
# ```ruby
|
193
193
|
# Array(["a", "b"]) #=> ["a", "b"]
|
194
194
|
# Array(1..5) #=> [1, 2, 3, 4, 5]
|
@@ -245,7 +245,7 @@ module Kernel
|
|
245
245
|
# at the point of call. This object can be used when calling `eval` to
|
246
246
|
# execute the evaluated command in this environment. See also the
|
247
247
|
# description of class `Binding` .
|
248
|
-
#
|
248
|
+
#
|
249
249
|
# ```ruby
|
250
250
|
# def get_binding(param)
|
251
251
|
# binding
|
@@ -260,7 +260,7 @@ module Kernel
|
|
260
260
|
# to return a status code to the invoking environment. `true` and `FALSE`
|
261
261
|
# of *status* means success and failure respectively. The interpretation
|
262
262
|
# of other integer values are system dependent.
|
263
|
-
#
|
263
|
+
#
|
264
264
|
# ```ruby
|
265
265
|
# begin
|
266
266
|
# exit
|
@@ -270,25 +270,25 @@ module Kernel
|
|
270
270
|
# end
|
271
271
|
# puts "after begin block"
|
272
272
|
# ```
|
273
|
-
#
|
273
|
+
#
|
274
274
|
# *produces:*
|
275
|
-
#
|
275
|
+
#
|
276
276
|
# rescued a SystemExit exception
|
277
277
|
# after begin block
|
278
|
-
#
|
278
|
+
#
|
279
279
|
# Just prior to termination, Ruby executes any `at_exit` functions (see
|
280
280
|
# Kernel::at\_exit) and runs any object finalizers (see
|
281
281
|
# [ObjectSpace.define\_finalizer](https://ruby-doc.org/core-2.6.3/ObjectSpace.html#method-c-define_finalizer)
|
282
282
|
# ).
|
283
|
-
#
|
283
|
+
#
|
284
284
|
# ```ruby
|
285
285
|
# at_exit { puts "at_exit function" }
|
286
286
|
# ObjectSpace.define_finalizer("string", proc { puts "in finalizer" })
|
287
287
|
# exit
|
288
288
|
# ```
|
289
|
-
#
|
289
|
+
#
|
290
290
|
# *produces:*
|
291
|
-
#
|
291
|
+
#
|
292
292
|
# at_exit function
|
293
293
|
# in finalizer
|
294
294
|
def exit: () -> bot
|
@@ -325,7 +325,7 @@ module Kernel
|
|
325
325
|
def gets: (?String arg0, ?Integer arg1) -> String?
|
326
326
|
|
327
327
|
# Returns an array of the names of global variables.
|
328
|
-
#
|
328
|
+
#
|
329
329
|
# ```ruby
|
330
330
|
# global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
|
331
331
|
# ```
|
@@ -334,9 +334,9 @@ module Kernel
|
|
334
334
|
def load: (String filename, ?bool arg0) -> bool
|
335
335
|
|
336
336
|
# Repeatedly executes the block.
|
337
|
-
#
|
337
|
+
#
|
338
338
|
# If no block is given, an enumerator is returned instead.
|
339
|
-
#
|
339
|
+
#
|
340
340
|
# ```ruby
|
341
341
|
# loop do
|
342
342
|
# print "Input: "
|
@@ -345,18 +345,18 @@ module Kernel
|
|
345
345
|
# # ...
|
346
346
|
# end
|
347
347
|
# ```
|
348
|
-
#
|
348
|
+
#
|
349
349
|
# [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html)
|
350
350
|
# raised in the block breaks the loop. In this case, loop returns the
|
351
351
|
# "result" value stored in the exception.
|
352
|
-
#
|
352
|
+
#
|
353
353
|
# ```ruby
|
354
354
|
# enum = Enumerator.new { |y|
|
355
355
|
# y << "one"
|
356
356
|
# y << "two"
|
357
357
|
# :ok
|
358
358
|
# }
|
359
|
-
#
|
359
|
+
#
|
360
360
|
# result = loop {
|
361
361
|
# puts enum.next
|
362
362
|
# } #=> :ok
|
@@ -372,16 +372,16 @@ module Kernel
|
|
372
372
|
# the output record separator ( `$\` ) is not `nil`, it will be appended
|
373
373
|
# to the output. If no arguments are given, prints `$_` . Objects that
|
374
374
|
# aren’t strings will be converted by calling their `to_s` method.
|
375
|
-
#
|
375
|
+
#
|
376
376
|
# ```ruby
|
377
377
|
# print "cat", [1,2,3], 99, "\n"
|
378
378
|
# $, = ", "
|
379
379
|
# $\ = "\n"
|
380
380
|
# print "cat", [1,2,3], 99
|
381
381
|
# ```
|
382
|
-
#
|
382
|
+
#
|
383
383
|
# *produces:*
|
384
|
-
#
|
384
|
+
#
|
385
385
|
# cat12399
|
386
386
|
# cat, 1, 2, 3, 99
|
387
387
|
def print: (*Kernel args) -> nil
|
@@ -408,35 +408,35 @@ module Kernel
|
|
408
408
|
# If called without an argument, or if `max.to_i.abs == 0`, rand returns
|
409
409
|
# a pseudo-random floating point number between 0.0 and 1.0, including 0.0
|
410
410
|
# and excluding 1.0.
|
411
|
-
#
|
411
|
+
#
|
412
412
|
# ```ruby
|
413
413
|
# rand #=> 0.2725926052826416
|
414
414
|
# ```
|
415
|
-
#
|
415
|
+
#
|
416
416
|
# When `max.abs` is greater than or equal to 1, `rand` returns a
|
417
417
|
# pseudo-random integer greater than or equal to 0 and less than
|
418
418
|
# `max.to_i.abs` .
|
419
|
-
#
|
419
|
+
#
|
420
420
|
# ```ruby
|
421
421
|
# rand(100) #=> 12
|
422
422
|
# ```
|
423
|
-
#
|
423
|
+
#
|
424
424
|
# When `max` is a [Range](https://ruby-doc.org/core-2.6.3/Range.html),
|
425
425
|
# `rand` returns a random number where range.member?(number) == true.
|
426
|
-
#
|
426
|
+
#
|
427
427
|
# Negative or floating point values for `max` are allowed, but may give
|
428
428
|
# surprising results.
|
429
|
-
#
|
429
|
+
#
|
430
430
|
# ```ruby
|
431
431
|
# rand(-100) # => 87
|
432
432
|
# rand(-0.5) # => 0.8130921818028143
|
433
433
|
# rand(1.9) # equivalent to rand(1), which is always 0
|
434
434
|
# ```
|
435
|
-
#
|
435
|
+
#
|
436
436
|
# [\#srand](Kernel.downloaded.ruby_doc#method-i-srand) may be used to
|
437
437
|
# ensure that sequences of random numbers are reproducible between
|
438
438
|
# different runs of a program.
|
439
|
-
#
|
439
|
+
#
|
440
440
|
# See also
|
441
441
|
# [Random\#rand](https://ruby-doc.org/core-2.6.3/Random.html#method-i-rand)
|
442
442
|
# .
|
@@ -468,109 +468,109 @@ module Kernel
|
|
468
468
|
|
469
469
|
# Replaces the current process by running the given external *command* ,
|
470
470
|
# which can take one of the following forms:
|
471
|
-
#
|
471
|
+
#
|
472
472
|
# - `exec(commandline)`
|
473
473
|
# command line string which is passed to the standard shell
|
474
|
-
#
|
474
|
+
#
|
475
475
|
# - `exec(cmdname, arg1, ...)`
|
476
476
|
# command name and one or more arguments (no shell)
|
477
|
-
#
|
477
|
+
#
|
478
478
|
# - `exec([cmdname, argv0], arg1, ...)`
|
479
479
|
# command name, [argv](https://ruby-doc.org/core-2.6.3/0) and zero or
|
480
480
|
# more arguments (no shell)
|
481
|
-
#
|
481
|
+
#
|
482
482
|
# In the first form, the string is taken as a command line that is subject
|
483
483
|
# to shell expansion before being executed.
|
484
|
-
#
|
484
|
+
#
|
485
485
|
# The standard shell always means `"/bin/sh"` on Unix-like systems, same
|
486
486
|
# as `ENV["RUBYSHELL"]` (or `ENV["COMSPEC"]` on Windows NT series), and
|
487
487
|
# similar.
|
488
|
-
#
|
488
|
+
#
|
489
489
|
# If the string from the first form ( `exec("command")` ) follows these
|
490
490
|
# simple rules:
|
491
|
-
#
|
491
|
+
#
|
492
492
|
# - no meta characters
|
493
|
-
#
|
493
|
+
#
|
494
494
|
# - no shell reserved word and no special built-in
|
495
|
-
#
|
495
|
+
#
|
496
496
|
# - Ruby invokes the command directly without shell
|
497
|
-
#
|
497
|
+
#
|
498
498
|
# You can force shell invocation by adding “;” to the string (because “;”
|
499
499
|
# is a meta character).
|
500
|
-
#
|
500
|
+
#
|
501
501
|
# Note that this behavior is observable by pid obtained (return value of
|
502
502
|
# spawn() and
|
503
503
|
# [IO\#pid](https://ruby-doc.org/core-2.6.3/IO.html#method-i-pid) for
|
504
504
|
# [IO.popen](https://ruby-doc.org/core-2.6.3/IO.html#method-c-popen) ) is
|
505
505
|
# the pid of the invoked command, not shell.
|
506
|
-
#
|
506
|
+
#
|
507
507
|
# In the second form ( `exec("command1", "arg1", ...)` ), the first is
|
508
508
|
# taken as a command name and the rest are passed as parameters to command
|
509
509
|
# with no shell expansion.
|
510
|
-
#
|
510
|
+
#
|
511
511
|
# In the third form ( `exec(["command", "argv0"], "arg1", ...)` ),
|
512
512
|
# starting a two-element array at the beginning of the command, the first
|
513
513
|
# element is the command to be executed, and the second argument is used
|
514
514
|
# as the `argv[0]` value, which may show up in process listings.
|
515
|
-
#
|
515
|
+
#
|
516
516
|
# In order to execute the command, one of the `exec(2)` system calls are
|
517
517
|
# used, so the running command may inherit some of the environment of the
|
518
518
|
# original program (including open file descriptors).
|
519
|
-
#
|
519
|
+
#
|
520
520
|
# This behavior is modified by the given `env` and `options` parameters.
|
521
521
|
# See ::spawn for details.
|
522
|
-
#
|
522
|
+
#
|
523
523
|
# If the command fails to execute (typically `Errno::ENOENT` when it was
|
524
524
|
# not found) a
|
525
525
|
# [SystemCallError](https://ruby-doc.org/core-2.6.3/SystemCallError.html)
|
526
526
|
# exception is raised.
|
527
|
-
#
|
527
|
+
#
|
528
528
|
# This method modifies process attributes according to given `options`
|
529
529
|
# before `exec(2)` system call. See ::spawn for more details about the
|
530
530
|
# given `options` .
|
531
|
-
#
|
531
|
+
#
|
532
532
|
# The modified attributes may be retained when `exec(2)` system call
|
533
533
|
# fails.
|
534
|
-
#
|
534
|
+
#
|
535
535
|
# For example, hard resource limits are not restorable.
|
536
|
-
#
|
536
|
+
#
|
537
537
|
# Consider to create a child process using ::spawn or
|
538
538
|
# [\#system](Kernel.downloaded.ruby_doc#method-i-system) if this is not
|
539
539
|
# acceptable.
|
540
|
-
#
|
540
|
+
#
|
541
541
|
# ```ruby
|
542
542
|
# exec "echo *" # echoes list of files in current directory
|
543
543
|
# # never get here
|
544
|
-
#
|
544
|
+
#
|
545
545
|
# exec "echo", "*" # echoes an asterisk
|
546
546
|
# # never get here
|
547
547
|
# ```
|
548
548
|
def exec: (*String args) -> bot
|
549
549
|
|
550
550
|
# Executes *command…* in a subshell. *command…* is one of following forms.
|
551
|
-
#
|
551
|
+
#
|
552
552
|
# commandline : command line string which is passed to the standard shell
|
553
553
|
# cmdname, arg1, ... : command name and one or more arguments (no shell)
|
554
554
|
# [cmdname, argv0], arg1, ... : command name, argv[0] and zero or more arguments (no shell)
|
555
|
-
#
|
555
|
+
#
|
556
556
|
# system returns `true` if the command gives zero exit status, `false` for
|
557
557
|
# non zero exit status. Returns `nil` if command execution fails. An error
|
558
558
|
# status is available in `$?` . The arguments are processed in the same
|
559
559
|
# way as for `Kernel.spawn` .
|
560
|
-
#
|
560
|
+
#
|
561
561
|
# The hash arguments, env and options, are same as `exec` and `spawn` .
|
562
562
|
# See `Kernel.spawn` for details.
|
563
|
-
#
|
563
|
+
#
|
564
564
|
# ```ruby
|
565
565
|
# system("echo *")
|
566
566
|
# system("echo", "*")
|
567
567
|
# ```
|
568
|
-
#
|
568
|
+
#
|
569
569
|
# *produces:*
|
570
|
-
#
|
570
|
+
#
|
571
571
|
# config.h main.rb
|
572
572
|
# *
|
573
|
-
#
|
573
|
+
#
|
574
574
|
# See `Kernel.exec` for the standard shell.
|
575
575
|
def system: (*String args) -> (NilClass | FalseClass | TrueClass)
|
576
576
|
end
|
@@ -95,7 +95,7 @@ class MatchData
|
|
95
95
|
# f3 #=> "113"
|
96
96
|
# f4 #=> "8"
|
97
97
|
#
|
98
|
-
def captures: () -> ::Array[String?]
|
98
|
+
def captures: () -> ::Array[String?]
|
99
99
|
|
100
100
|
# Returns the offset of the character immediately following the end of the *n*th
|
101
101
|
# element of the match array in the string. *n* can be a string or symbol to
|
data/stdlib/builtin/method.rbs
CHANGED
@@ -4,7 +4,7 @@ class Method < Object
|
|
4
4
|
|
5
5
|
# Invokes the *meth* with the specified arguments, returning the method’s
|
6
6
|
# return value.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# ```ruby
|
9
9
|
# m = 12.method("+")
|
10
10
|
# m.call(3) #=> 15
|
@@ -15,12 +15,12 @@ class Method < Object
|
|
15
15
|
# Returns a proc that is the composition of this method and the given *g*
|
16
16
|
# . The returned proc takes a variable number of arguments, calls *g* with
|
17
17
|
# them then calls this method with the result.
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# ```ruby
|
20
20
|
# def f(x)
|
21
21
|
# x * x
|
22
22
|
# end
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# f = self.method(:f)
|
25
25
|
# g = proc {|x| x + x }
|
26
26
|
# p (f << g).call(2) #=> 16
|
@@ -30,10 +30,10 @@ class Method < Object
|
|
30
30
|
# Invokes the method with `obj` as the parameter like
|
31
31
|
# [call](Method.downloaded.ruby_doc#method-i-call). This allows a method
|
32
32
|
# object to be the target of a `when` clause in a case statement.
|
33
|
-
#
|
33
|
+
#
|
34
34
|
# ```ruby
|
35
35
|
# require 'prime'
|
36
|
-
#
|
36
|
+
#
|
37
37
|
# case 1373
|
38
38
|
# when Prime.method(:prime?)
|
39
39
|
# # ...
|
@@ -44,12 +44,12 @@ class Method < Object
|
|
44
44
|
# Returns a proc that is the composition of this method and the given *g*
|
45
45
|
# . The returned proc takes a variable number of arguments, calls *g* with
|
46
46
|
# them then calls this method with the result.
|
47
|
-
#
|
47
|
+
#
|
48
48
|
# ```ruby
|
49
49
|
# def f(x)
|
50
50
|
# x * x
|
51
51
|
# end
|
52
|
-
#
|
52
|
+
#
|
53
53
|
# f = self.method(:f)
|
54
54
|
# g = proc {|x| x + x }
|
55
55
|
# p (f >> g).call(2) #=> 8
|
@@ -58,7 +58,7 @@ class Method < Object
|
|
58
58
|
|
59
59
|
# Invokes the *meth* with the specified arguments, returning the method’s
|
60
60
|
# return value.
|
61
|
-
#
|
61
|
+
#
|
62
62
|
# ```ruby
|
63
63
|
# m = 12.method("+")
|
64
64
|
# m.call(3) #=> 15
|
@@ -74,7 +74,7 @@ class Method < Object
|
|
74
74
|
# argument being mandatory if any keyword argument is mandatory. For
|
75
75
|
# methods written in C, returns -1 if the call takes a variable number of
|
76
76
|
# arguments.
|
77
|
-
#
|
77
|
+
#
|
78
78
|
# class C
|
79
79
|
# def one; end
|
80
80
|
# def two(a); end
|
@@ -98,7 +98,7 @@ class Method < Object
|
|
98
98
|
# c.method(:eight).arity #=> 1
|
99
99
|
# c.method(:nine).arity #=> 1
|
100
100
|
# c.method(:ten).arity #=> -2
|
101
|
-
#
|
101
|
+
#
|
102
102
|
# "cat".method(:size).arity #=> 0
|
103
103
|
# "cat".method(:replace).arity #=> 1
|
104
104
|
# "cat".method(:squeeze).arity #=> -1
|
@@ -106,14 +106,14 @@ class Method < Object
|
|
106
106
|
def arity: () -> Integer
|
107
107
|
|
108
108
|
# Returns a clone of this method.
|
109
|
-
#
|
109
|
+
#
|
110
110
|
# ```ruby
|
111
111
|
# class A
|
112
112
|
# def foo
|
113
113
|
# return "bar"
|
114
114
|
# end
|
115
115
|
# end
|
116
|
-
#
|
116
|
+
#
|
117
117
|
# m = A.new.method(:foo)
|
118
118
|
# m.call # => "bar"
|
119
119
|
# n = m.clone.call # => "bar"
|
@@ -126,7 +126,7 @@ class Method < Object
|
|
126
126
|
def name: () -> Symbol
|
127
127
|
|
128
128
|
# Returns the original name of the method.
|
129
|
-
#
|
129
|
+
#
|
130
130
|
# ```ruby
|
131
131
|
# class C
|
132
132
|
# def foo; end
|
@@ -137,24 +137,24 @@ class Method < Object
|
|
137
137
|
def original_name: () -> Symbol
|
138
138
|
|
139
139
|
# Returns the class or module that defines the method. See also receiver.
|
140
|
-
#
|
140
|
+
#
|
141
141
|
# ```ruby
|
142
142
|
# (1..3).method(:map).owner #=> Enumerable
|
143
143
|
# ```
|
144
144
|
def owner: () -> (Class | Module)
|
145
145
|
|
146
146
|
# Returns the parameter information of this method.
|
147
|
-
#
|
147
|
+
#
|
148
148
|
# ```ruby
|
149
149
|
# def foo(bar); end
|
150
150
|
# method(:foo).parameters #=> [[:req, :bar]]
|
151
|
-
#
|
151
|
+
#
|
152
152
|
# def foo(bar, baz, bat, &blk); end
|
153
153
|
# method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:req, :bat], [:block, :blk]]
|
154
|
-
#
|
154
|
+
#
|
155
155
|
# def foo(bar, *args); end
|
156
156
|
# method(:foo).parameters #=> [[:req, :bar], [:rest, :args]]
|
157
|
-
#
|
157
|
+
#
|
158
158
|
# def foo(bar, baz, *args, &blk); end
|
159
159
|
# method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:rest, :args], [:block, :blk]]
|
160
160
|
# ```
|
@@ -164,7 +164,7 @@ class Method < Object
|
|
164
164
|
]
|
165
165
|
|
166
166
|
# Returns the bound receiver of the method object.
|
167
|
-
#
|
167
|
+
#
|
168
168
|
# ```ruby
|
169
169
|
# (1..3).method(:map).receiver # => 1..3
|
170
170
|
# ```
|