rbs 3.2.2 → 3.3.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +1 -1
- data/.github/workflows/ruby.yml +7 -2
- data/CHANGELOG.md +85 -0
- data/Gemfile.lock +14 -14
- data/README.md +11 -2
- data/Rakefile +10 -7
- data/Steepfile +7 -7
- data/core/basic_object.rbs +7 -7
- data/core/binding.rbs +3 -3
- data/core/builtin.rbs +171 -5
- data/core/constants.rbs +17 -17
- data/core/dir.rbs +3 -3
- data/core/encoding.rbs +434 -628
- data/core/enumerator.rbs +37 -0
- data/core/exception.rbs +11 -11
- data/core/false_class.rbs +5 -11
- data/core/fiber.rbs +3 -3
- data/core/file_test.rbs +28 -26
- data/core/kernel.rbs +900 -21
- data/core/marshal.rbs +24 -14
- data/core/match_data.rbs +8 -8
- data/core/math.rbs +57 -53
- data/core/method.rbs +3 -1
- data/core/module.rbs +38 -36
- data/core/nil_class.rbs +7 -13
- data/core/object.rbs +3 -966
- data/core/process.rbs +3 -3
- data/core/ractor.rbs +2 -2
- data/core/rb_config.rbs +64 -43
- data/core/regexp.rbs +3 -3
- data/core/signal.rbs +10 -4
- data/core/struct.rbs +1 -1
- data/core/thread.rbs +7 -7
- data/core/thread_group.rbs +9 -9
- data/core/true_class.rbs +5 -11
- data/core/unbound_method.rbs +56 -7
- data/core/warning.rbs +33 -0
- data/docs/collection.md +56 -6
- data/docs/data_and_struct.md +57 -0
- data/docs/stdlib.md +61 -2
- data/docs/syntax.md +123 -2
- data/ext/rbs_extension/lexer.c +624 -569
- data/ext/rbs_extension/lexer.h +1 -0
- data/ext/rbs_extension/lexer.re +1 -0
- data/ext/rbs_extension/lexstate.c +1 -0
- data/ext/rbs_extension/parser.c +6 -0
- data/goodcheck.yml +2 -2
- data/lib/rbs/annotate/formatter.rb +13 -3
- data/lib/rbs/annotate/rdoc_source.rb +10 -1
- data/lib/rbs/cli/colored_io.rb +48 -0
- data/lib/rbs/cli/diff.rb +80 -0
- data/lib/rbs/cli.rb +151 -16
- data/lib/rbs/collection/config/lockfile.rb +0 -25
- data/lib/rbs/collection/config/lockfile_generator.rb +0 -6
- data/lib/rbs/collection/installer.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +6 -4
- data/lib/rbs/collection/sources/local.rb +7 -5
- data/lib/rbs/diff.rb +104 -0
- data/lib/rbs/environment.rb +1 -1
- data/lib/rbs/method_type.rb +23 -0
- data/lib/rbs/prototype/rb.rb +2 -9
- data/lib/rbs/prototype/runtime/helpers.rb +59 -0
- data/lib/rbs/prototype/runtime/value_object_generator.rb +236 -0
- data/lib/rbs/prototype/runtime.rb +234 -150
- data/lib/rbs/sorter.rb +144 -117
- data/lib/rbs/test/guaranteed.rb +31 -0
- data/lib/rbs/test/type_check.rb +4 -4
- data/lib/rbs/test.rb +3 -0
- data/lib/rbs/types.rb +184 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +4 -4
- data/lib/rbs.rb +1 -0
- data/rbs.gemspec +1 -0
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +1 -1
- data/sig/cli/colored_io.rbs +15 -0
- data/sig/cli/diff.rbs +21 -0
- data/sig/cli.rbs +2 -0
- data/sig/collection/config/lockfile.rbs +0 -6
- data/sig/diff.rbs +23 -0
- data/sig/errors.rbs +1 -5
- data/sig/method_types.rbs +6 -0
- data/sig/prototype/runtime.rbs +108 -0
- data/sig/rdoc/rbs.rbs +4 -0
- data/sig/shims/bundler.rbs +5 -0
- data/sig/sorter.rbs +23 -5
- data/sig/types.rbs +29 -0
- data/stdlib/benchmark/0/benchmark.rbs +1 -1
- data/stdlib/cgi/0/core.rbs +2 -2
- data/stdlib/did_you_mean/0/did_you_mean.rbs +2 -2
- data/stdlib/digest/0/digest.rbs +1 -1
- data/stdlib/fileutils/0/fileutils.rbs +1 -1
- data/stdlib/forwardable/0/forwardable.rbs +4 -4
- data/stdlib/io-console/0/io-console.rbs +1 -1
- data/stdlib/json/0/json.rbs +37 -0
- data/stdlib/logger/0/logger.rbs +2 -2
- data/stdlib/net-http/0/manifest.yaml +1 -1
- data/stdlib/net-http/0/net-http.rbs +16 -63
- data/stdlib/net-protocol/0/manifest.yaml +2 -0
- data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
- data/stdlib/openssl/0/openssl.rbs +1 -1
- data/stdlib/pp/0/manifest.yaml +2 -0
- data/stdlib/pp/0/pp.rbs +301 -0
- data/stdlib/{yaml → psych}/0/dbm.rbs +3 -3
- data/stdlib/psych/0/manifest.yaml +3 -0
- data/stdlib/psych/0/psych.rbs +391 -0
- data/stdlib/{yaml → psych}/0/store.rbs +2 -2
- data/stdlib/rdoc/0/code_object.rbs +55 -0
- data/stdlib/rdoc/0/comment.rbs +60 -0
- data/stdlib/rdoc/0/context.rbs +153 -0
- data/stdlib/rdoc/0/markup.rbs +119 -0
- data/stdlib/rdoc/0/parser.rbs +56 -0
- data/stdlib/rdoc/0/rdoc.rbs +0 -372
- data/stdlib/rdoc/0/ri.rbs +17 -0
- data/stdlib/rdoc/0/store.rbs +48 -0
- data/stdlib/rdoc/0/top_level.rbs +97 -0
- data/stdlib/socket/0/basic_socket.rbs +1 -1
- data/stdlib/socket/0/socket.rbs +1 -1
- data/stdlib/uri/0/common.rbs +1 -1
- data/stdlib/yaml/0/manifest.yaml +1 -2
- data/stdlib/yaml/0/yaml.rbs +1 -199
- metadata +46 -9
- data/sig/shims/pp.rbs +0 -3
- data/sig/shims.rbs +0 -47
data/core/process.rbs
CHANGED
@@ -401,7 +401,7 @@ module Process
|
|
401
401
|
# Process::RLIM_SAVED_MAX or Process::RLIM_SAVED_CUR. See Process.setrlimit and
|
402
402
|
# the system getrlimit(2) manual for details.
|
403
403
|
#
|
404
|
-
def self.getrlimit: (
|
404
|
+
def self.getrlimit: (interned | Integer resource) -> [ Integer, Integer ]
|
405
405
|
|
406
406
|
# <!--
|
407
407
|
# rdoc-file=process.c
|
@@ -523,7 +523,7 @@ module Process
|
|
523
523
|
# because of no privilege, will be raised. In these cases, signals may have
|
524
524
|
# been sent to preceding processes.
|
525
525
|
#
|
526
|
-
def self.kill: (Integer |
|
526
|
+
def self.kill: (Integer | interned signal, *Integer pids) -> Integer
|
527
527
|
|
528
528
|
# <!--
|
529
529
|
# rdoc-file=process.c
|
@@ -673,7 +673,7 @@ module Process
|
|
673
673
|
#
|
674
674
|
# Process.setrlimit(:CORE, Process.getrlimit(:CORE)[1])
|
675
675
|
#
|
676
|
-
def self.setrlimit: (
|
676
|
+
def self.setrlimit: (interned | Integer resource, Integer cur_limit, ?Integer max_limit) -> nil
|
677
677
|
|
678
678
|
# <!--
|
679
679
|
# rdoc-file=process.c
|
data/core/ractor.rbs
CHANGED
@@ -599,7 +599,7 @@ class Ractor
|
|
599
599
|
# -->
|
600
600
|
# get a value from ractor-local storage
|
601
601
|
#
|
602
|
-
def []: (
|
602
|
+
def []: (interned sym) -> untyped
|
603
603
|
|
604
604
|
# <!--
|
605
605
|
# rdoc-file=ractor.rb
|
@@ -607,7 +607,7 @@ class Ractor
|
|
607
607
|
# -->
|
608
608
|
# set a value in ractor-local storage
|
609
609
|
#
|
610
|
-
def []=: [T] (
|
610
|
+
def []=: [T] (interned sym, T val) -> T
|
611
611
|
|
612
612
|
# <!--
|
613
613
|
# rdoc-file=ractor.rb
|
data/core/rb_config.rbs
CHANGED
@@ -7,6 +7,49 @@
|
|
7
7
|
# built.
|
8
8
|
#
|
9
9
|
module RbConfig
|
10
|
+
# <!-- rdoc-file=rbconfig.rb -->
|
11
|
+
# The hash configurations stored.
|
12
|
+
#
|
13
|
+
CONFIG: Hash[String, String]
|
14
|
+
|
15
|
+
# <!-- rdoc-file=rbconfig.rb -->
|
16
|
+
# DESTDIR on make install.
|
17
|
+
#
|
18
|
+
DESTDIR: String
|
19
|
+
|
20
|
+
# <!-- rdoc-file=rbconfig.rb -->
|
21
|
+
# Almost same with CONFIG. MAKEFILE_CONFIG has other variable reference like
|
22
|
+
# below.
|
23
|
+
#
|
24
|
+
# MAKEFILE_CONFIG["bindir"] = "$(exec_prefix)/bin"
|
25
|
+
#
|
26
|
+
# The values of this constant is used for creating Makefile.
|
27
|
+
#
|
28
|
+
# require 'rbconfig'
|
29
|
+
#
|
30
|
+
# print <<-END_OF_MAKEFILE
|
31
|
+
# prefix = #{RbConfig::MAKEFILE_CONFIG['prefix']}
|
32
|
+
# exec_prefix = #{RbConfig::MAKEFILE_CONFIG['exec_prefix']}
|
33
|
+
# bindir = #{RbConfig::MAKEFILE_CONFIG['bindir']}
|
34
|
+
# END_OF_MAKEFILE
|
35
|
+
#
|
36
|
+
# => prefix = /usr/local
|
37
|
+
# exec_prefix = $(prefix)
|
38
|
+
# bindir = $(exec_prefix)/bin MAKEFILE_CONFIG = {}
|
39
|
+
#
|
40
|
+
# RbConfig.expand is used for resolving references like above in rbconfig.
|
41
|
+
#
|
42
|
+
# require 'rbconfig'
|
43
|
+
# p RbConfig.expand(RbConfig::MAKEFILE_CONFIG["bindir"])
|
44
|
+
# # => "/usr/local/bin"
|
45
|
+
#
|
46
|
+
MAKEFILE_CONFIG: Hash[String, String]
|
47
|
+
|
48
|
+
# <!-- rdoc-file=rbconfig.rb -->
|
49
|
+
# Ruby installed directory.
|
50
|
+
#
|
51
|
+
TOPDIR: String
|
52
|
+
|
10
53
|
# <!--
|
11
54
|
# rdoc-file=rbconfig.rb
|
12
55
|
# - RbConfig.expand(val) -> string
|
@@ -18,50 +61,28 @@ module RbConfig
|
|
18
61
|
#
|
19
62
|
def self.expand: (String val, ?Hash[String, String] config) -> String
|
20
63
|
|
64
|
+
# <!--
|
65
|
+
# rdoc-file=rbconfig.rb
|
66
|
+
# - RbConfig.fire_update!(key, val) -> array
|
67
|
+
# - RbConfig.fire_update!(key, val, mkconf, conf) -> array
|
68
|
+
# -->
|
69
|
+
# updates `key+ in `mkconf` with `val`, and all values depending on
|
70
|
+
# the `key` in `mkconf`.
|
71
|
+
#
|
72
|
+
# RbConfig::MAKEFILE_CONFIG.values_at("CC", "LDSHARED") # => ["gcc", "$(CC) -shared"]
|
73
|
+
# RbConfig::CONFIG.values_at("CC", "LDSHARED") # => ["gcc", "gcc -shared"]
|
74
|
+
# RbConfig.fire_update!("CC", "gcc-8") # => ["CC", "LDSHARED"]
|
75
|
+
# RbConfig::MAKEFILE_CONFIG.values_at("CC", "LDSHARED") # => ["gcc-8", "$(CC) -shared"]
|
76
|
+
# RbConfig::CONFIG.values_at("CC", "LDSHARED") # => ["gcc-8", "gcc-8 -shared"]
|
77
|
+
#
|
78
|
+
# returns updated keys list, or `nil` if nothing changed.
|
21
79
|
def self.fire_update!: (String key, String val, ?Hash[String, String] mkconf, ?Hash[String, String] conf) -> Array[String]?
|
22
80
|
|
81
|
+
# <!--
|
82
|
+
# rdoc-file=rbconfig.rb
|
83
|
+
# - RbConfig.ruby -> path
|
84
|
+
# -->
|
85
|
+
#
|
86
|
+
# returns the absolute pathname of the ruby command.
|
23
87
|
def self.ruby: () -> String
|
24
88
|
end
|
25
|
-
|
26
|
-
# <!-- rdoc-file=rbconfig.rb -->
|
27
|
-
# The hash configurations stored.
|
28
|
-
#
|
29
|
-
RbConfig::CONFIG: Hash[String, String]
|
30
|
-
|
31
|
-
# <!-- rdoc-file=rbconfig.rb -->
|
32
|
-
# DESTDIR on make install.
|
33
|
-
#
|
34
|
-
RbConfig::DESTDIR: String
|
35
|
-
|
36
|
-
# <!-- rdoc-file=rbconfig.rb -->
|
37
|
-
# Almost same with CONFIG. MAKEFILE_CONFIG has other variable reference like
|
38
|
-
# below.
|
39
|
-
#
|
40
|
-
# MAKEFILE_CONFIG["bindir"] = "$(exec_prefix)/bin"
|
41
|
-
#
|
42
|
-
# The values of this constant is used for creating Makefile.
|
43
|
-
#
|
44
|
-
# require 'rbconfig'
|
45
|
-
#
|
46
|
-
# print <<-END_OF_MAKEFILE
|
47
|
-
# prefix = #{RbConfig::MAKEFILE_CONFIG['prefix']}
|
48
|
-
# exec_prefix = #{RbConfig::MAKEFILE_CONFIG['exec_prefix']}
|
49
|
-
# bindir = #{RbConfig::MAKEFILE_CONFIG['bindir']}
|
50
|
-
# END_OF_MAKEFILE
|
51
|
-
#
|
52
|
-
# => prefix = /usr/local
|
53
|
-
# exec_prefix = $(prefix)
|
54
|
-
# bindir = $(exec_prefix)/bin MAKEFILE_CONFIG = {}
|
55
|
-
#
|
56
|
-
# RbConfig.expand is used for resolving references like above in rbconfig.
|
57
|
-
#
|
58
|
-
# require 'rbconfig'
|
59
|
-
# p RbConfig.expand(RbConfig::MAKEFILE_CONFIG["bindir"])
|
60
|
-
# # => "/usr/local/bin"
|
61
|
-
#
|
62
|
-
RbConfig::MAKEFILE_CONFIG: Hash[String, String]
|
63
|
-
|
64
|
-
# <!-- rdoc-file=rbconfig.rb -->
|
65
|
-
# Ruby installed directory.
|
66
|
-
#
|
67
|
-
RbConfig::TOPDIR: String
|
data/core/regexp.rbs
CHANGED
@@ -849,7 +849,7 @@ class Regexp
|
|
849
849
|
#
|
850
850
|
# Regexp.quote is an alias for Regexp.escape.
|
851
851
|
#
|
852
|
-
def self.escape: (
|
852
|
+
def self.escape: (interned str) -> String
|
853
853
|
|
854
854
|
# <!--
|
855
855
|
# rdoc-file=re.c
|
@@ -889,7 +889,7 @@ class Regexp
|
|
889
889
|
#
|
890
890
|
def self.last_match: () -> MatchData?
|
891
891
|
| (Integer n) -> String?
|
892
|
-
| (
|
892
|
+
| (interned n) -> String?
|
893
893
|
|
894
894
|
# <!--
|
895
895
|
# rdoc-file=re.c
|
@@ -928,7 +928,7 @@ class Regexp
|
|
928
928
|
#
|
929
929
|
# Regexp.quote is an alias for Regexp.escape.
|
930
930
|
#
|
931
|
-
def self.quote: (
|
931
|
+
def self.quote: (interned str) -> String
|
932
932
|
|
933
933
|
# <!--
|
934
934
|
# rdoc-file=re.c
|
data/core/signal.rbs
CHANGED
@@ -45,7 +45,7 @@ module Signal
|
|
45
45
|
#
|
46
46
|
# Signal.list #=> {"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "IOT"=>6, "ABRT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
|
47
47
|
#
|
48
|
-
def self
|
48
|
+
def self?.list: () -> Hash[String, Integer]
|
49
49
|
|
50
50
|
# <!--
|
51
51
|
# rdoc-file=signal.c
|
@@ -61,7 +61,7 @@ module Signal
|
|
61
61
|
#
|
62
62
|
# INT
|
63
63
|
#
|
64
|
-
def self
|
64
|
+
def self?.signame: (int signo) -> String?
|
65
65
|
|
66
66
|
# <!--
|
67
67
|
# rdoc-file=signal.c
|
@@ -89,6 +89,12 @@ module Signal
|
|
89
89
|
# Child died
|
90
90
|
# Terminating: 27460
|
91
91
|
#
|
92
|
-
def self
|
93
|
-
|
92
|
+
def self?.trap: (Integer | interned signal) { (Integer) -> void } -> trap_command
|
93
|
+
| (Integer | interned signal, trap_command command) -> trap_command
|
94
|
+
|
95
|
+
type trap_command = string | bool | nil | _TrapCommand
|
96
|
+
|
97
|
+
interface _TrapCommand
|
98
|
+
def call: (Integer signo) -> void
|
99
|
+
end
|
94
100
|
end
|
data/core/struct.rbs
CHANGED
data/core/thread.rbs
CHANGED
@@ -226,7 +226,7 @@ class Thread < Object
|
|
226
226
|
# For thread-local variables, please see #thread_variable_get and
|
227
227
|
# #thread_variable_set.
|
228
228
|
#
|
229
|
-
def []: (
|
229
|
+
def []: (interned key) -> untyped
|
230
230
|
|
231
231
|
# <!--
|
232
232
|
# rdoc-file=thread.c
|
@@ -240,7 +240,7 @@ class Thread < Object
|
|
240
240
|
# For thread-local variables, please see #thread_variable_set and
|
241
241
|
# #thread_variable_get.
|
242
242
|
#
|
243
|
-
def []=: (
|
243
|
+
def []=: (interned key, untyped value) -> untyped
|
244
244
|
|
245
245
|
# <!--
|
246
246
|
# rdoc-file=thread.c
|
@@ -676,7 +676,7 @@ class Thread < Object
|
|
676
676
|
# Note that these are not fiber local variables. Please see Thread#[] and
|
677
677
|
# Thread#thread_variable_get for more details.
|
678
678
|
#
|
679
|
-
def thread_variable?: (
|
679
|
+
def thread_variable?: (interned key) -> bool
|
680
680
|
|
681
681
|
# <!--
|
682
682
|
# rdoc-file=thread.c
|
@@ -1741,10 +1741,10 @@ class Thread::SizedQueue < Thread::Queue
|
|
1741
1741
|
def push: (untyped obj, ?boolish non_block, timeout: _ToF?) -> void
|
1742
1742
|
end
|
1743
1743
|
|
1744
|
-
ConditionVariable
|
1744
|
+
class ConditionVariable = Thread::ConditionVariable
|
1745
1745
|
|
1746
|
-
Mutex
|
1746
|
+
class Mutex = Thread::Mutex
|
1747
1747
|
|
1748
|
-
Queue
|
1748
|
+
class Queue = Thread::Queue
|
1749
1749
|
|
1750
|
-
SizedQueue
|
1750
|
+
class SizedQueue = Thread::SizedQueue
|
data/core/thread_group.rbs
CHANGED
@@ -8,7 +8,13 @@
|
|
8
8
|
# Newly created threads belong to the same group as the thread from which they
|
9
9
|
# were created.
|
10
10
|
#
|
11
|
-
class ThreadGroup
|
11
|
+
class ThreadGroup
|
12
|
+
# <!-- rdoc-file=thread.c -->
|
13
|
+
# The default ThreadGroup created when Ruby starts; all Threads belong to it by
|
14
|
+
# default.
|
15
|
+
#
|
16
|
+
Default: ThreadGroup
|
17
|
+
|
12
18
|
# <!--
|
13
19
|
# rdoc-file=thread.c
|
14
20
|
# - thgrp.add(thread) -> thgrp
|
@@ -34,7 +40,7 @@ class ThreadGroup < Object
|
|
34
40
|
# Initial group now #<Thread:0x401b3c18>#<Thread:0x401bdf4c>
|
35
41
|
# tg group now #<Thread:0x401b3c90>
|
36
42
|
#
|
37
|
-
def add: (Thread thread) ->
|
43
|
+
def add: (Thread thread) -> self
|
38
44
|
|
39
45
|
# <!--
|
40
46
|
# rdoc-file=thread.c
|
@@ -69,11 +75,5 @@ class ThreadGroup < Object
|
|
69
75
|
#
|
70
76
|
# ThreadGroup::Default.list #=> [#<Thread:0x401bdf4c run>]
|
71
77
|
#
|
72
|
-
def list: () ->
|
78
|
+
def list: () -> Array[Thread]
|
73
79
|
end
|
74
|
-
|
75
|
-
# <!-- rdoc-file=thread.c -->
|
76
|
-
# The default ThreadGroup created when Ruby starts; all Threads belong to it by
|
77
|
-
# default.
|
78
|
-
#
|
79
|
-
ThreadGroup::Default: ThreadGroup
|
data/core/true_class.rbs
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
# allowing `true` to be used in logical expressions.
|
5
5
|
#
|
6
6
|
class TrueClass
|
7
|
-
public
|
8
|
-
|
9
7
|
def !: () -> false
|
10
8
|
|
11
9
|
# <!--
|
@@ -14,9 +12,8 @@ class TrueClass
|
|
14
12
|
# -->
|
15
13
|
# And---Returns `false` if *obj* is `nil` or `false`, `true` otherwise.
|
16
14
|
#
|
17
|
-
def &: (nil) -> false
|
18
|
-
| (
|
19
|
-
| (untyped obj) -> true
|
15
|
+
def &: (false | nil) -> false
|
16
|
+
| (untyped obj) -> bool
|
20
17
|
|
21
18
|
# <!--
|
22
19
|
# rdoc-file=object.c
|
@@ -27,7 +24,7 @@ class TrueClass
|
|
27
24
|
# statements.
|
28
25
|
#
|
29
26
|
def ===: (true) -> true
|
30
|
-
| (untyped obj) ->
|
27
|
+
| (untyped obj) -> bool
|
31
28
|
|
32
29
|
# <!--
|
33
30
|
# rdoc-file=object.c
|
@@ -35,9 +32,8 @@ class TrueClass
|
|
35
32
|
# -->
|
36
33
|
# Exclusive Or---Returns `true` if *obj* is `nil` or `false`, `false` otherwise.
|
37
34
|
#
|
38
|
-
def ^: (nil) -> true
|
39
|
-
| (
|
40
|
-
| (untyped obj) -> false
|
35
|
+
def ^: (false | nil) -> true
|
36
|
+
| (untyped obj) -> bool
|
41
37
|
|
42
38
|
# <!-- rdoc-file=object.c -->
|
43
39
|
# The string representation of `true` is "true".
|
@@ -67,6 +63,4 @@ class TrueClass
|
|
67
63
|
# or
|
68
64
|
#
|
69
65
|
def |: (untyped obj) -> true
|
70
|
-
|
71
|
-
def clone: (?freeze: true?) -> self
|
72
66
|
end
|
data/core/unbound_method.rbs
CHANGED
@@ -60,7 +60,29 @@ class UnboundMethod
|
|
60
60
|
# Array.instance_method(:sum) == Enumerable.instance_method(:sum)
|
61
61
|
# #=> false, Array redefines the method for efficiency
|
62
62
|
#
|
63
|
-
def ==: (untyped) -> bool
|
63
|
+
def ==: (untyped other) -> bool
|
64
|
+
|
65
|
+
# <!-- rdoc-file=proc.c -->
|
66
|
+
# Two unbound method objects are equal if they refer to the same method
|
67
|
+
# definition.
|
68
|
+
#
|
69
|
+
# Array.instance_method(:each_slice) == Enumerable.instance_method(:each_slice)
|
70
|
+
# #=> true
|
71
|
+
#
|
72
|
+
# Array.instance_method(:sum) == Enumerable.instance_method(:sum)
|
73
|
+
# #=> false, Array redefines the method for efficiency
|
74
|
+
#
|
75
|
+
alias eql? ==
|
76
|
+
|
77
|
+
# <!--
|
78
|
+
# rdoc-file=proc.c
|
79
|
+
# - meth.hash -> integer
|
80
|
+
# -->
|
81
|
+
# Returns a hash value corresponding to the method object.
|
82
|
+
#
|
83
|
+
# See also Object#hash.
|
84
|
+
#
|
85
|
+
def hash: () -> Integer
|
64
86
|
|
65
87
|
# <!--
|
66
88
|
# rdoc-file=proc.c
|
@@ -78,7 +100,7 @@ class UnboundMethod
|
|
78
100
|
# m.call # => "bar"
|
79
101
|
# n = m.clone.call # => "bar"
|
80
102
|
#
|
81
|
-
def clone: () ->
|
103
|
+
def clone: () -> instance
|
82
104
|
|
83
105
|
# <!--
|
84
106
|
# rdoc-file=proc.c
|
@@ -189,6 +211,34 @@ class UnboundMethod
|
|
189
211
|
#
|
190
212
|
def inspect: () -> String
|
191
213
|
|
214
|
+
# <!-- rdoc-file=proc.c -->
|
215
|
+
# Returns a human-readable description of the underlying method.
|
216
|
+
#
|
217
|
+
# "cat".method(:count).inspect #=> "#<Method: String#count(*)>"
|
218
|
+
# (1..3).method(:map).inspect #=> "#<Method: Range(Enumerable)#map()>"
|
219
|
+
#
|
220
|
+
# In the latter case, the method description includes the "owner" of the
|
221
|
+
# original method (`Enumerable` module, which is included into `Range`).
|
222
|
+
#
|
223
|
+
# `inspect` also provides, when possible, method argument names (call sequence)
|
224
|
+
# and source location.
|
225
|
+
#
|
226
|
+
# require 'net/http'
|
227
|
+
# Net::HTTP.method(:get).inspect
|
228
|
+
# #=> "#<Method: Net::HTTP.get(uri_or_host, path=..., port=...) <skip>/lib/ruby/2.7.0/net/http.rb:457>"
|
229
|
+
#
|
230
|
+
# `...` in argument definition means argument is optional (has some default
|
231
|
+
# value).
|
232
|
+
#
|
233
|
+
# For methods defined in C (language core and extensions), location and argument
|
234
|
+
# names can't be extracted, and only generic information is provided in form of
|
235
|
+
# `*` (any number of arguments) or `_` (some positional argument).
|
236
|
+
#
|
237
|
+
# "cat".method(:count).inspect #=> "#<Method: String#count(*)>"
|
238
|
+
# "cat".method(:+).inspect #=> "#<Method: String#+(_)>""
|
239
|
+
#
|
240
|
+
alias to_s inspect
|
241
|
+
|
192
242
|
# <!--
|
193
243
|
# rdoc-file=proc.c
|
194
244
|
# - meth.name -> symbol
|
@@ -213,7 +263,7 @@ class UnboundMethod
|
|
213
263
|
#
|
214
264
|
# (1..3).method(:map).owner #=> Enumerable
|
215
265
|
#
|
216
|
-
def owner: () -> Module
|
266
|
+
def owner: () -> (Class | Module)
|
217
267
|
|
218
268
|
# <!--
|
219
269
|
# rdoc-file=proc.c
|
@@ -233,8 +283,7 @@ class UnboundMethod
|
|
233
283
|
# def foo(bar, baz, *args, &blk); end
|
234
284
|
# method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:rest, :args], [:block, :blk]]
|
235
285
|
#
|
236
|
-
def parameters: () -> ::
|
237
|
-
| () -> ::Array[[ Symbol ]]
|
286
|
+
def parameters: () -> Method::param_types
|
238
287
|
|
239
288
|
# <!--
|
240
289
|
# rdoc-file=proc.c
|
@@ -243,7 +292,7 @@ class UnboundMethod
|
|
243
292
|
# Returns the Ruby source filename and line number containing this method or nil
|
244
293
|
# if this method was not defined in Ruby (i.e. native).
|
245
294
|
#
|
246
|
-
def source_location: () -> [
|
295
|
+
def source_location: () -> [String, Integer]?
|
247
296
|
|
248
297
|
# <!--
|
249
298
|
# rdoc-file=proc.c
|
@@ -276,5 +325,5 @@ class UnboundMethod
|
|
276
325
|
# arguments. This is semantically equivalent to `umeth.bind(recv).call(args,
|
277
326
|
# ...)`.
|
278
327
|
#
|
279
|
-
def bind_call: (untyped recv, *untyped
|
328
|
+
def bind_call: (untyped recv, *untyped, **untyped) ?{ (*untyped, **untyped) -> untyped } -> untyped
|
280
329
|
end
|
data/core/warning.rbs
CHANGED
@@ -29,8 +29,41 @@
|
|
29
29
|
# The `warning` gem provides convenient ways to customize Warning.warn.
|
30
30
|
#
|
31
31
|
module Warning
|
32
|
+
# The types of categories the `Warning` module understands.
|
33
|
+
#
|
32
34
|
type category = :deprecated | :experimental
|
33
35
|
|
36
|
+
# <!--
|
37
|
+
# rdoc-file=error.c
|
38
|
+
# - Warning[category] -> true or false
|
39
|
+
# -->
|
40
|
+
# Returns the flag to show the warning messages for `category`. Supported
|
41
|
+
# categories are:
|
42
|
+
#
|
43
|
+
# `:deprecated`
|
44
|
+
# : deprecation warnings
|
45
|
+
#
|
46
|
+
# * assignment of non-nil value to `$,` and `$;`
|
47
|
+
# * keyword arguments
|
48
|
+
# * proc/lambda without block
|
49
|
+
#
|
50
|
+
# etc.
|
51
|
+
#
|
52
|
+
# `:experimental`
|
53
|
+
# : experimental features
|
54
|
+
#
|
55
|
+
# * Pattern matching
|
56
|
+
#
|
57
|
+
def self.[]: (category) -> bool
|
58
|
+
|
59
|
+
# <!--
|
60
|
+
# rdoc-file=error.c
|
61
|
+
# - Warning[category] = flag -> flag
|
62
|
+
# -->
|
63
|
+
# Sets the warning flags for `category`. See Warning.[] for the categories.
|
64
|
+
#
|
65
|
+
def self.[]=: [T] (category, T flag) -> T
|
66
|
+
|
34
67
|
# <!--
|
35
68
|
# rdoc-file=error.c
|
36
69
|
# - warn(msg, category: nil) -> nil
|
data/docs/collection.md
CHANGED
@@ -28,11 +28,10 @@ sources:
|
|
28
28
|
# A directory to install the downloaded RBSs
|
29
29
|
path: .gem_rbs_collection
|
30
30
|
|
31
|
-
gems:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
ignore: true
|
31
|
+
# gems:
|
32
|
+
# # If you want to avoid installing rbs files for gems, you can specify them here.
|
33
|
+
# - name: GEM_NAME
|
34
|
+
# ignore: true
|
36
35
|
```
|
37
36
|
|
38
37
|
I also recommend updating `.gitignore`.
|
@@ -79,7 +78,7 @@ sources:
|
|
79
78
|
revision: main
|
80
79
|
repo_dir: gems
|
81
80
|
|
82
|
-
# You can also add a local path as a collection source
|
81
|
+
# You can also add a local path as a collection source optionally.
|
83
82
|
- type: local
|
84
83
|
path: path/to/local/dir
|
85
84
|
|
@@ -99,6 +98,57 @@ gems:
|
|
99
98
|
ignore: true
|
100
99
|
```
|
101
100
|
|
101
|
+
### Avoid installing RBS
|
102
|
+
|
103
|
+
There are two ways to avoid RBS installation.
|
104
|
+
|
105
|
+
#### `require: false` in `Gemfile`
|
106
|
+
|
107
|
+
First, you can specify `require: false` in `Gemfile`. It is the recommended way to avoid installing RBS.
|
108
|
+
For example:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
# Gemfile
|
112
|
+
|
113
|
+
gem 'GEM_NAME', require: false
|
114
|
+
```
|
115
|
+
|
116
|
+
In this case, `rbs collection` doesn't install the RBS of `GEM_NAME`.
|
117
|
+
We recommend to specify `require: false` for `rbs` gem itself because `rbs` gem's RBS file is not necessary in most cases.
|
118
|
+
|
119
|
+
#### `ignore: true` in `rbs_collection.yaml`
|
120
|
+
|
121
|
+
Second, you can write `ignore: true` in `rbs_collection.yaml`. It is useful if you want to avoid installing RBS but you need to require the gem.
|
122
|
+
|
123
|
+
```yaml
|
124
|
+
# rbs_collection.yaml
|
125
|
+
|
126
|
+
gems:
|
127
|
+
- name: GEM_NAME
|
128
|
+
ignore: true
|
129
|
+
```
|
130
|
+
|
131
|
+
#### Load RBS specified `require: false`
|
132
|
+
|
133
|
+
You can also use `ignore: false` if you want to install RBS for a gem which you specify `require: false` in `Gemfile`.
|
134
|
+
For example:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
# Gemfile
|
138
|
+
|
139
|
+
gem 'GEM_NAME', require: false
|
140
|
+
```
|
141
|
+
|
142
|
+
```yaml
|
143
|
+
# rbs_collection.yaml
|
144
|
+
|
145
|
+
gems:
|
146
|
+
- name: GEM_NAME
|
147
|
+
ignore: false
|
148
|
+
```
|
149
|
+
|
150
|
+
In this case, `rbs collection` installs the RBS of `GEM_NAME`.
|
151
|
+
|
102
152
|
### `manifest.yaml`
|
103
153
|
|
104
154
|
If you are a gem maintainer, you can write `manifest.yaml`.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Using `Data` and `Struct`
|
2
|
+
|
3
|
+
`Data` and `Struct` are commonly used utilities to define simple *value* objects. The objects have attributes, and the equality between the two objects are defined by equality of the attributes. (Note that we can define additional methods and overwrite the equality definitions when we want.)
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
# Defines `Measure` class with `#amount` and `#unit` attributes
|
7
|
+
Measure = Data.define(:amount, :unit)
|
8
|
+
```
|
9
|
+
|
10
|
+
Unfortunately, supporting `Data` and `Struct` in RBS is not straightforward. You have to write down the attribute definitions and initializers in RBS.
|
11
|
+
|
12
|
+
```rbs
|
13
|
+
class Measure
|
14
|
+
# `attr_accessor amount: Integer` in the case of Struct
|
15
|
+
attr_reader amount: Integer
|
16
|
+
|
17
|
+
# `attr_accessor unit: String` in the case of Struct
|
18
|
+
attr_reader unit: String
|
19
|
+
|
20
|
+
def initialize: (Integer amount, String unit) -> void
|
21
|
+
| (amount: Integer, unit: String) -> void
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
This is simplified definition of the `Measure` class, for the case you only use the attributes and initializers. You can add more method definitions or inherit from `Data` class to make the definition more complete.
|
26
|
+
|
27
|
+
However, it's common that you don't need all of the `Data` and `Struct` methods, like `.members` and `.[]`. When you are using those utility classes just for the attributes methods, you can simply ignore other methods or skip specifying a super class.
|
28
|
+
|
29
|
+
> You may want to implement a generator that understands `Data.define` and `Struct.new`. But even with the generator, you need to edit the generated RBS files so that the attribute definitions have correct types.
|
30
|
+
|
31
|
+
## Type checking class definitions using `Data` and `Struct`
|
32
|
+
|
33
|
+
If you use Steep, you may need additional annotation in Ruby implementation.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# Type error because return type of `Data.define(...)` is not `singleton(Measure)`
|
37
|
+
Measure = Data.define(:amount, :unit)
|
38
|
+
```
|
39
|
+
|
40
|
+
You can please the type checker by adding a cast (`_`) or define the class inheriting from `Data.define(...)`.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# Skip type checking by assigning to `_`
|
44
|
+
Measure = _ = Data.define(:amount, :unit)
|
45
|
+
|
46
|
+
# Super class is not type checked by Steep
|
47
|
+
class Measure < Data.define(:amount, :unit)
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
@soutaro has prefered inheriting from `Data.define`, but you may find an extra annonymous class in `.ancestors` [^1].
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Measure.ancestors #=> [Measure, #<Class:0xOOF>, Data, ...]
|
55
|
+
```
|
56
|
+
|
57
|
+
[^1]: [Shannon Skipper](https://github.com/havenwood) told me it in Discord
|