rbs 0.12.0 → 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 +10 -10
- data/.gitignore +0 -1
- data/CHANGELOG.md +24 -0
- data/Gemfile +3 -0
- data/README.md +8 -2
- data/Rakefile +9 -4
- data/Steepfile +1 -0
- data/bin/annotate-with-rdoc +1 -1
- data/bin/setup +0 -2
- data/bin/test_runner.rb +3 -6
- data/docs/CONTRIBUTING.md +1 -0
- data/goodcheck.yml +22 -5
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/cli.rb +12 -4
- data/lib/rbs/constant.rb +1 -1
- data/lib/rbs/constant_table.rb +9 -8
- data/lib/rbs/definition_builder.rb +4 -5
- data/lib/rbs/environment.rb +5 -1
- data/lib/rbs/environment_loader.rb +12 -12
- 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 +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +25 -15
- data/sig/constant.rbs +21 -0
- data/sig/constant_table.rbs +30 -0
- data/sig/declarations.rbs +1 -1
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +4 -5
- data/sig/environment_loader.rbs +54 -0
- 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/version.rbs +3 -0
- data/sig/writer.rbs +40 -0
- 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 +70 -68
- 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 +2 -0
- data/stdlib/pty/pty.rbs +5 -29
- data/stdlib/tmpdir/tmpdir.rbs +12 -12
- data/stdlib/uri/generic.rbs +1 -1
- data/stdlib/uri/http.rbs +158 -0
- data/stdlib/uri/https.rbs +108 -0
- data/stdlib/uri/ldap.rbs +224 -0
- data/stdlib/uri/ldaps.rbs +108 -0
- data/steep/Gemfile.lock +13 -17
- metadata +12 -3
data/stdlib/builtin/kernel.rbs
CHANGED
@@ -1,16 +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
|
+
private
|
15
|
+
|
14
16
|
def caller: (?Integer start_or_range, ?Integer length) -> ::Array[String]?
|
15
17
|
| (?::Range[Integer] start_or_range) -> ::Array[String]?
|
16
18
|
| () -> ::Array[String]
|
@@ -22,13 +24,13 @@ module Kernel
|
|
22
24
|
| () { (Object tag) -> untyped } -> untyped
|
23
25
|
|
24
26
|
# In a perfect world this should be:
|
25
|
-
#
|
27
|
+
#
|
26
28
|
# returns(T.class_of(T.self_type))
|
27
|
-
#
|
29
|
+
#
|
28
30
|
# but that doesn't work (yet). Even making it:
|
29
|
-
#
|
31
|
+
#
|
30
32
|
# returns(Class)
|
31
|
-
#
|
33
|
+
#
|
32
34
|
# is very surprising since users expect their methods to be present.
|
33
35
|
# So we settle for untyped.
|
34
36
|
def `class`: () -> untyped
|
@@ -40,7 +42,7 @@ module Kernel
|
|
40
42
|
|
41
43
|
# Returns `true` if `yield` would execute a block in the current context.
|
42
44
|
# The `iterator?` form is mildly deprecated.
|
43
|
-
#
|
45
|
+
#
|
44
46
|
# ```ruby
|
45
47
|
# def try
|
46
48
|
# if block_given?
|
@@ -57,7 +59,7 @@ module Kernel
|
|
57
59
|
alias block_given? iterator?
|
58
60
|
|
59
61
|
# Returns the names of the current local variables.
|
60
|
-
#
|
62
|
+
#
|
61
63
|
# ```ruby
|
62
64
|
# fred = 1
|
63
65
|
# for i in 1..10
|
@@ -100,12 +102,12 @@ module Kernel
|
|
100
102
|
# collect the termination statuses of its children or use `Process.detach`
|
101
103
|
# to register disinterest in their status; otherwise, the operating system
|
102
104
|
# may accumulate zombie processes.
|
103
|
-
#
|
105
|
+
#
|
104
106
|
# The thread calling fork is the only thread in the created child process.
|
105
107
|
# fork doesn’t copy other threads.
|
106
|
-
#
|
108
|
+
#
|
107
109
|
# If fork is not usable, Process.respond\_to?(:fork) returns false.
|
108
|
-
#
|
110
|
+
#
|
109
111
|
# Note that fork(2) is not available on some platforms like Windows and
|
110
112
|
# NetBSD 4. Therefore you should use spawn() instead of fork().
|
111
113
|
def fork: () -> Integer?
|
@@ -177,16 +179,16 @@ module Kernel
|
|
177
179
|
|
178
180
|
# Returns `arg` as an [Array](https://ruby-doc.org/core-2.6.3/Array.html)
|
179
181
|
# .
|
180
|
-
#
|
182
|
+
#
|
181
183
|
# First tries to call `to_ary` on `arg`, then `to_a` . If `arg` does not
|
182
184
|
# respond to `to_ary` or `to_a`, returns an
|
183
185
|
# [Array](https://ruby-doc.org/core-2.6.3/Array.html) of length 1
|
184
186
|
# containing `arg` .
|
185
|
-
#
|
187
|
+
#
|
186
188
|
# If `to_ary` or `to_a` returns something other than an
|
187
189
|
# [Array](https://ruby-doc.org/core-2.6.3/Array.html), raises a
|
188
190
|
# `TypeError` .
|
189
|
-
#
|
191
|
+
#
|
190
192
|
# ```ruby
|
191
193
|
# Array(["a", "b"]) #=> ["a", "b"]
|
192
194
|
# Array(1..5) #=> [1, 2, 3, 4, 5]
|
@@ -243,7 +245,7 @@ module Kernel
|
|
243
245
|
# at the point of call. This object can be used when calling `eval` to
|
244
246
|
# execute the evaluated command in this environment. See also the
|
245
247
|
# description of class `Binding` .
|
246
|
-
#
|
248
|
+
#
|
247
249
|
# ```ruby
|
248
250
|
# def get_binding(param)
|
249
251
|
# binding
|
@@ -258,7 +260,7 @@ module Kernel
|
|
258
260
|
# to return a status code to the invoking environment. `true` and `FALSE`
|
259
261
|
# of *status* means success and failure respectively. The interpretation
|
260
262
|
# of other integer values are system dependent.
|
261
|
-
#
|
263
|
+
#
|
262
264
|
# ```ruby
|
263
265
|
# begin
|
264
266
|
# exit
|
@@ -268,25 +270,25 @@ module Kernel
|
|
268
270
|
# end
|
269
271
|
# puts "after begin block"
|
270
272
|
# ```
|
271
|
-
#
|
273
|
+
#
|
272
274
|
# *produces:*
|
273
|
-
#
|
275
|
+
#
|
274
276
|
# rescued a SystemExit exception
|
275
277
|
# after begin block
|
276
|
-
#
|
278
|
+
#
|
277
279
|
# Just prior to termination, Ruby executes any `at_exit` functions (see
|
278
280
|
# Kernel::at\_exit) and runs any object finalizers (see
|
279
281
|
# [ObjectSpace.define\_finalizer](https://ruby-doc.org/core-2.6.3/ObjectSpace.html#method-c-define_finalizer)
|
280
282
|
# ).
|
281
|
-
#
|
283
|
+
#
|
282
284
|
# ```ruby
|
283
285
|
# at_exit { puts "at_exit function" }
|
284
286
|
# ObjectSpace.define_finalizer("string", proc { puts "in finalizer" })
|
285
287
|
# exit
|
286
288
|
# ```
|
287
|
-
#
|
289
|
+
#
|
288
290
|
# *produces:*
|
289
|
-
#
|
291
|
+
#
|
290
292
|
# at_exit function
|
291
293
|
# in finalizer
|
292
294
|
def exit: () -> bot
|
@@ -323,7 +325,7 @@ module Kernel
|
|
323
325
|
def gets: (?String arg0, ?Integer arg1) -> String?
|
324
326
|
|
325
327
|
# Returns an array of the names of global variables.
|
326
|
-
#
|
328
|
+
#
|
327
329
|
# ```ruby
|
328
330
|
# global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
|
329
331
|
# ```
|
@@ -332,9 +334,9 @@ module Kernel
|
|
332
334
|
def load: (String filename, ?bool arg0) -> bool
|
333
335
|
|
334
336
|
# Repeatedly executes the block.
|
335
|
-
#
|
337
|
+
#
|
336
338
|
# If no block is given, an enumerator is returned instead.
|
337
|
-
#
|
339
|
+
#
|
338
340
|
# ```ruby
|
339
341
|
# loop do
|
340
342
|
# print "Input: "
|
@@ -343,18 +345,18 @@ module Kernel
|
|
343
345
|
# # ...
|
344
346
|
# end
|
345
347
|
# ```
|
346
|
-
#
|
348
|
+
#
|
347
349
|
# [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html)
|
348
350
|
# raised in the block breaks the loop. In this case, loop returns the
|
349
351
|
# "result" value stored in the exception.
|
350
|
-
#
|
352
|
+
#
|
351
353
|
# ```ruby
|
352
354
|
# enum = Enumerator.new { |y|
|
353
355
|
# y << "one"
|
354
356
|
# y << "two"
|
355
357
|
# :ok
|
356
358
|
# }
|
357
|
-
#
|
359
|
+
#
|
358
360
|
# result = loop {
|
359
361
|
# puts enum.next
|
360
362
|
# } #=> :ok
|
@@ -370,16 +372,16 @@ module Kernel
|
|
370
372
|
# the output record separator ( `$\` ) is not `nil`, it will be appended
|
371
373
|
# to the output. If no arguments are given, prints `$_` . Objects that
|
372
374
|
# aren’t strings will be converted by calling their `to_s` method.
|
373
|
-
#
|
375
|
+
#
|
374
376
|
# ```ruby
|
375
377
|
# print "cat", [1,2,3], 99, "\n"
|
376
378
|
# $, = ", "
|
377
379
|
# $\ = "\n"
|
378
380
|
# print "cat", [1,2,3], 99
|
379
381
|
# ```
|
380
|
-
#
|
382
|
+
#
|
381
383
|
# *produces:*
|
382
|
-
#
|
384
|
+
#
|
383
385
|
# cat12399
|
384
386
|
# cat, 1, 2, 3, 99
|
385
387
|
def print: (*Kernel args) -> nil
|
@@ -406,35 +408,35 @@ module Kernel
|
|
406
408
|
# If called without an argument, or if `max.to_i.abs == 0`, rand returns
|
407
409
|
# a pseudo-random floating point number between 0.0 and 1.0, including 0.0
|
408
410
|
# and excluding 1.0.
|
409
|
-
#
|
411
|
+
#
|
410
412
|
# ```ruby
|
411
413
|
# rand #=> 0.2725926052826416
|
412
414
|
# ```
|
413
|
-
#
|
415
|
+
#
|
414
416
|
# When `max.abs` is greater than or equal to 1, `rand` returns a
|
415
417
|
# pseudo-random integer greater than or equal to 0 and less than
|
416
418
|
# `max.to_i.abs` .
|
417
|
-
#
|
419
|
+
#
|
418
420
|
# ```ruby
|
419
421
|
# rand(100) #=> 12
|
420
422
|
# ```
|
421
|
-
#
|
423
|
+
#
|
422
424
|
# When `max` is a [Range](https://ruby-doc.org/core-2.6.3/Range.html),
|
423
425
|
# `rand` returns a random number where range.member?(number) == true.
|
424
|
-
#
|
426
|
+
#
|
425
427
|
# Negative or floating point values for `max` are allowed, but may give
|
426
428
|
# surprising results.
|
427
|
-
#
|
429
|
+
#
|
428
430
|
# ```ruby
|
429
431
|
# rand(-100) # => 87
|
430
432
|
# rand(-0.5) # => 0.8130921818028143
|
431
433
|
# rand(1.9) # equivalent to rand(1), which is always 0
|
432
434
|
# ```
|
433
|
-
#
|
435
|
+
#
|
434
436
|
# [\#srand](Kernel.downloaded.ruby_doc#method-i-srand) may be used to
|
435
437
|
# ensure that sequences of random numbers are reproducible between
|
436
438
|
# different runs of a program.
|
437
|
-
#
|
439
|
+
#
|
438
440
|
# See also
|
439
441
|
# [Random\#rand](https://ruby-doc.org/core-2.6.3/Random.html#method-i-rand)
|
440
442
|
# .
|
@@ -466,109 +468,109 @@ module Kernel
|
|
466
468
|
|
467
469
|
# Replaces the current process by running the given external *command* ,
|
468
470
|
# which can take one of the following forms:
|
469
|
-
#
|
471
|
+
#
|
470
472
|
# - `exec(commandline)`
|
471
473
|
# command line string which is passed to the standard shell
|
472
|
-
#
|
474
|
+
#
|
473
475
|
# - `exec(cmdname, arg1, ...)`
|
474
476
|
# command name and one or more arguments (no shell)
|
475
|
-
#
|
477
|
+
#
|
476
478
|
# - `exec([cmdname, argv0], arg1, ...)`
|
477
479
|
# command name, [argv](https://ruby-doc.org/core-2.6.3/0) and zero or
|
478
480
|
# more arguments (no shell)
|
479
|
-
#
|
481
|
+
#
|
480
482
|
# In the first form, the string is taken as a command line that is subject
|
481
483
|
# to shell expansion before being executed.
|
482
|
-
#
|
484
|
+
#
|
483
485
|
# The standard shell always means `"/bin/sh"` on Unix-like systems, same
|
484
486
|
# as `ENV["RUBYSHELL"]` (or `ENV["COMSPEC"]` on Windows NT series), and
|
485
487
|
# similar.
|
486
|
-
#
|
488
|
+
#
|
487
489
|
# If the string from the first form ( `exec("command")` ) follows these
|
488
490
|
# simple rules:
|
489
|
-
#
|
491
|
+
#
|
490
492
|
# - no meta characters
|
491
|
-
#
|
493
|
+
#
|
492
494
|
# - no shell reserved word and no special built-in
|
493
|
-
#
|
495
|
+
#
|
494
496
|
# - Ruby invokes the command directly without shell
|
495
|
-
#
|
497
|
+
#
|
496
498
|
# You can force shell invocation by adding “;” to the string (because “;”
|
497
499
|
# is a meta character).
|
498
|
-
#
|
500
|
+
#
|
499
501
|
# Note that this behavior is observable by pid obtained (return value of
|
500
502
|
# spawn() and
|
501
503
|
# [IO\#pid](https://ruby-doc.org/core-2.6.3/IO.html#method-i-pid) for
|
502
504
|
# [IO.popen](https://ruby-doc.org/core-2.6.3/IO.html#method-c-popen) ) is
|
503
505
|
# the pid of the invoked command, not shell.
|
504
|
-
#
|
506
|
+
#
|
505
507
|
# In the second form ( `exec("command1", "arg1", ...)` ), the first is
|
506
508
|
# taken as a command name and the rest are passed as parameters to command
|
507
509
|
# with no shell expansion.
|
508
|
-
#
|
510
|
+
#
|
509
511
|
# In the third form ( `exec(["command", "argv0"], "arg1", ...)` ),
|
510
512
|
# starting a two-element array at the beginning of the command, the first
|
511
513
|
# element is the command to be executed, and the second argument is used
|
512
514
|
# as the `argv[0]` value, which may show up in process listings.
|
513
|
-
#
|
515
|
+
#
|
514
516
|
# In order to execute the command, one of the `exec(2)` system calls are
|
515
517
|
# used, so the running command may inherit some of the environment of the
|
516
518
|
# original program (including open file descriptors).
|
517
|
-
#
|
519
|
+
#
|
518
520
|
# This behavior is modified by the given `env` and `options` parameters.
|
519
521
|
# See ::spawn for details.
|
520
|
-
#
|
522
|
+
#
|
521
523
|
# If the command fails to execute (typically `Errno::ENOENT` when it was
|
522
524
|
# not found) a
|
523
525
|
# [SystemCallError](https://ruby-doc.org/core-2.6.3/SystemCallError.html)
|
524
526
|
# exception is raised.
|
525
|
-
#
|
527
|
+
#
|
526
528
|
# This method modifies process attributes according to given `options`
|
527
529
|
# before `exec(2)` system call. See ::spawn for more details about the
|
528
530
|
# given `options` .
|
529
|
-
#
|
531
|
+
#
|
530
532
|
# The modified attributes may be retained when `exec(2)` system call
|
531
533
|
# fails.
|
532
|
-
#
|
534
|
+
#
|
533
535
|
# For example, hard resource limits are not restorable.
|
534
|
-
#
|
536
|
+
#
|
535
537
|
# Consider to create a child process using ::spawn or
|
536
538
|
# [\#system](Kernel.downloaded.ruby_doc#method-i-system) if this is not
|
537
539
|
# acceptable.
|
538
|
-
#
|
540
|
+
#
|
539
541
|
# ```ruby
|
540
542
|
# exec "echo *" # echoes list of files in current directory
|
541
543
|
# # never get here
|
542
|
-
#
|
544
|
+
#
|
543
545
|
# exec "echo", "*" # echoes an asterisk
|
544
546
|
# # never get here
|
545
547
|
# ```
|
546
548
|
def exec: (*String args) -> bot
|
547
549
|
|
548
550
|
# Executes *command…* in a subshell. *command…* is one of following forms.
|
549
|
-
#
|
551
|
+
#
|
550
552
|
# commandline : command line string which is passed to the standard shell
|
551
553
|
# cmdname, arg1, ... : command name and one or more arguments (no shell)
|
552
554
|
# [cmdname, argv0], arg1, ... : command name, argv[0] and zero or more arguments (no shell)
|
553
|
-
#
|
555
|
+
#
|
554
556
|
# system returns `true` if the command gives zero exit status, `false` for
|
555
557
|
# non zero exit status. Returns `nil` if command execution fails. An error
|
556
558
|
# status is available in `$?` . The arguments are processed in the same
|
557
559
|
# way as for `Kernel.spawn` .
|
558
|
-
#
|
560
|
+
#
|
559
561
|
# The hash arguments, env and options, are same as `exec` and `spawn` .
|
560
562
|
# See `Kernel.spawn` for details.
|
561
|
-
#
|
563
|
+
#
|
562
564
|
# ```ruby
|
563
565
|
# system("echo *")
|
564
566
|
# system("echo", "*")
|
565
567
|
# ```
|
566
|
-
#
|
568
|
+
#
|
567
569
|
# *produces:*
|
568
|
-
#
|
570
|
+
#
|
569
571
|
# config.h main.rb
|
570
572
|
# *
|
571
|
-
#
|
573
|
+
#
|
572
574
|
# See `Kernel.exec` for the standard shell.
|
573
575
|
def system: (*String args) -> (NilClass | FalseClass | TrueClass)
|
574
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
|
# ```
|