rbs 4.0.0.dev.4 → 4.1.0.pre.2
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/.clang-format +1 -0
- data/.github/dependabot.yml +16 -14
- data/.github/workflows/bundle-update.yml +63 -0
- data/.github/workflows/c-check.yml +21 -11
- data/.github/workflows/comments.yml +5 -3
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/jruby.yml +67 -0
- data/.github/workflows/milestone.yml +83 -0
- data/.github/workflows/ruby.yml +63 -24
- data/.github/workflows/rust.yml +184 -0
- data/.github/workflows/truffleruby.yml +54 -0
- data/.github/workflows/typecheck.yml +5 -2
- data/.github/workflows/wasm.yml +53 -0
- data/.github/workflows/windows.yml +8 -2
- data/.gitignore +11 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +357 -0
- data/README.md +4 -4
- data/Rakefile +365 -33
- data/Steepfile +8 -0
- data/config.yml +450 -24
- data/core/array.rbs +443 -363
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +9 -8
- data/core/class.rbs +11 -8
- data/core/comparable.rbs +55 -34
- data/core/complex.rbs +104 -78
- data/core/dir.rbs +61 -49
- data/core/encoding.rbs +12 -15
- data/core/enumerable.rbs +288 -196
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator/product.rbs +5 -5
- data/core/enumerator.rbs +91 -28
- data/core/errno.rbs +11 -2
- data/core/errors.rbs +58 -29
- data/core/exception.rbs +13 -13
- data/core/fiber.rbs +74 -54
- data/core/file.rbs +260 -1151
- data/core/file_constants.rbs +463 -0
- data/core/file_stat.rbs +534 -0
- data/core/file_test.rbs +3 -3
- data/core/float.rbs +257 -92
- data/core/gc.rbs +425 -281
- data/core/hash.rbs +1151 -829
- data/core/integer.rbs +156 -195
- data/core/io/buffer.rbs +53 -42
- data/core/io/wait.rbs +13 -35
- data/core/io.rbs +216 -150
- data/core/kernel.rbs +239 -163
- data/core/marshal.rbs +4 -4
- data/core/match_data.rbs +15 -13
- data/core/math.rbs +107 -66
- data/core/method.rbs +69 -33
- data/core/module.rbs +302 -150
- data/core/nil_class.rbs +7 -6
- data/core/numeric.rbs +77 -63
- data/core/object.rbs +9 -11
- data/core/object_space/weak_key_map.rbs +7 -7
- data/core/object_space.rbs +30 -23
- data/core/pathname.rbs +1322 -0
- data/core/proc.rbs +95 -58
- data/core/process.rbs +222 -202
- data/core/ractor.rbs +371 -515
- data/core/random.rbs +21 -3
- data/core/range.rbs +181 -79
- data/core/rational.rbs +60 -89
- data/core/rbs/ops.rbs +154 -0
- data/core/rbs/unnamed/argf.rbs +63 -56
- data/core/rbs/unnamed/env_class.rbs +19 -14
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +11 -118
- data/core/regexp.rbs +258 -214
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +78 -34
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +4 -71
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +16 -82
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +493 -363
- data/core/signal.rbs +26 -16
- data/core/string.rbs +3234 -1285
- data/core/struct.rbs +43 -42
- data/core/symbol.rbs +41 -34
- data/core/thread.rbs +141 -73
- data/core/time.rbs +81 -50
- data/core/trace_point.rbs +41 -35
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +24 -16
- data/core/warning.rbs +7 -7
- data/docs/CONTRIBUTING.md +2 -1
- data/docs/aliases.md +79 -0
- data/docs/collection.md +3 -3
- data/docs/config.md +171 -0
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +634 -0
- data/docs/rbs_by_example.md +20 -20
- data/docs/rust.md +96 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +48 -18
- data/docs/type_fingerprint.md +21 -0
- data/docs/wasm_serialization.md +80 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +1441 -671
- data/ext/rbs_extension/ast_translation.h +7 -0
- data/ext/rbs_extension/class_constants.c +18 -2
- data/ext/rbs_extension/class_constants.h +9 -0
- data/ext/rbs_extension/extconf.rb +6 -1
- data/ext/rbs_extension/legacy_location.c +33 -56
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +183 -39
- data/include/rbs/ast.h +597 -297
- data/include/rbs/defines.h +40 -0
- data/include/rbs/lexer.h +31 -11
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +6 -6
- data/include/rbs/serialize.h +39 -0
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/include/rbs.h +8 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +27 -31
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +335 -3
- data/lib/rbs/ast/ruby/comment_block.rb +30 -4
- data/lib/rbs/ast/ruby/declarations.rb +209 -4
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
- data/lib/rbs/ast/ruby/members.rb +571 -22
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +66 -24
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -106
- data/lib/rbs/cli.rb +55 -24
- data/lib/rbs/collection/config/lockfile_generator.rb +28 -3
- data/lib/rbs/collection/sources/git.rb +7 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +32 -6
- data/lib/rbs/definition_builder.rb +147 -25
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +235 -75
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -18
- data/lib/rbs/inline_parser.rb +377 -15
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/namespace.rb +47 -11
- data/lib/rbs/parser_aux.rb +20 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +3 -20
- data/lib/rbs/prototype/runtime.rb +10 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +120 -44
- data/lib/rbs/rewriter.rb +70 -0
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +25 -3
- data/lib/rbs/type_name.rb +34 -14
- data/lib/rbs/types.rb +88 -78
- data/lib/rbs/unit_test/type_assertions.rb +44 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/wasm/deserializer.rb +213 -0
- data/lib/rbs/wasm/location.rb +61 -0
- data/lib/rbs/wasm/parser.rb +137 -0
- data/lib/rbs/wasm/runtime.rb +217 -0
- data/lib/rbs/wasm/serialization_schema.rb +110 -0
- data/lib/rbs.rb +13 -2
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +24 -6
- data/schema/typeParam.json +17 -1
- data/sig/annotate/rdoc_annotater.rbs +12 -9
- data/sig/ast/ruby/annotations.rbs +364 -4
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +128 -2
- data/sig/buffer.rbs +19 -1
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/collection/config/lockfile_generator.rbs +2 -0
- data/sig/definition.rbs +6 -1
- data/sig/definition_builder.rbs +2 -0
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -14
- data/sig/inline_parser.rbs +41 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -2
- data/sig/method_builder.rbs +3 -1
- data/sig/namespace.rbs +20 -0
- data/sig/parser.rbs +41 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +36 -10
- data/sig/rewriter.rbs +45 -0
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/typename.rbs +15 -0
- data/sig/types.rbs +6 -7
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +15 -0
- data/sig/wasm/deserializer.rbs +66 -0
- data/sig/wasm/serialization_schema.rbs +13 -0
- data/src/ast.c +443 -162
- data/src/lexer.c +1415 -1313
- data/src/lexer.re +4 -0
- data/src/lexstate.c +63 -37
- data/src/location.c +7 -47
- data/src/parser.c +1032 -521
- data/src/serialize.c +958 -0
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -74
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -14
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/abbrev/0/array.rbs +1 -1
- data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +7 -4
- data/stdlib/csv/0/csv.rbs +5 -5
- data/stdlib/date/0/date.rbs +92 -79
- data/stdlib/date/0/date_time.rbs +25 -24
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/digest/0/digest.rbs +111 -1
- data/stdlib/erb/0/erb.rbs +748 -347
- data/stdlib/etc/0/etc.rbs +73 -54
- data/stdlib/fileutils/0/fileutils.rbs +179 -160
- data/stdlib/forwardable/0/forwardable.rbs +13 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +223 -142
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +162 -134
- data/stdlib/objspace/0/objspace.rbs +17 -34
- data/stdlib/open-uri/0/open-uri.rbs +48 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +482 -364
- data/stdlib/optparse/0/optparse.rbs +26 -17
- data/stdlib/pathname/0/pathname.rbs +11 -1381
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +65 -12
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +26 -69
- data/stdlib/ripper/0/ripper.rbs +22 -19
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +3 -3
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +23 -10
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +11 -3
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1209 -95
- data/stdlib/strscan/0/string_scanner.rbs +101 -80
- data/stdlib/tempfile/0/tempfile.rbs +25 -21
- data/stdlib/time/0/time.rbs +8 -6
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +4 -1
- data/stdlib/tsort/0/interfaces.rbs +8 -8
- data/stdlib/tsort/0/tsort.rbs +16 -15
- data/stdlib/uri/0/common.rbs +42 -20
- data/stdlib/uri/0/file.rbs +3 -3
- data/stdlib/uri/0/generic.rbs +26 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +8 -8
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- data/wasm/README.md +59 -0
- data/wasm/rbs_wasm.c +411 -0
- metadata +56 -8
- data/.vscode/extensions.json +0 -5
- data/.vscode/settings.json +0 -19
data/core/module.rbs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# methods may not. (See Module#module_function.)
|
|
7
7
|
#
|
|
8
8
|
# In the descriptions that follow, the parameter *sym* refers to a symbol, which
|
|
9
|
-
# is either a quoted string or a Symbol (such as
|
|
9
|
+
# is either a quoted string or a Symbol (such as <code>:name</code>).
|
|
10
10
|
#
|
|
11
11
|
# module Mod
|
|
12
12
|
# include Math
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
# Mod.constants #=> [:CONST, :PI, :E]
|
|
20
20
|
# Mod.instance_methods #=> [:meth]
|
|
21
21
|
#
|
|
22
|
-
class Module
|
|
22
|
+
class Module
|
|
23
23
|
# <!--
|
|
24
24
|
# rdoc-file=eval.c
|
|
25
25
|
# - Module.constants -> array
|
|
@@ -40,7 +40,7 @@ class Module < Object
|
|
|
40
40
|
#
|
|
41
41
|
# The second form calls the instance method `constants`.
|
|
42
42
|
#
|
|
43
|
-
def self.constants: () ->
|
|
43
|
+
def self.constants: (?boolish inherit) -> Array[Symbol]
|
|
44
44
|
|
|
45
45
|
# <!--
|
|
46
46
|
# rdoc-file=eval.c
|
|
@@ -56,7 +56,7 @@ class Module < Object
|
|
|
56
56
|
# $a #=> [M1::M2, M1]
|
|
57
57
|
# $a[0].name #=> "M1::M2"
|
|
58
58
|
#
|
|
59
|
-
def self.nesting: () ->
|
|
59
|
+
def self.nesting: () -> Array[Module]
|
|
60
60
|
|
|
61
61
|
# <!--
|
|
62
62
|
# rdoc-file=eval.c
|
|
@@ -79,11 +79,11 @@ class Module < Object
|
|
|
79
79
|
# using B
|
|
80
80
|
# p Module.used_modules
|
|
81
81
|
#
|
|
82
|
-
#
|
|
82
|
+
# <em>produces:</em>
|
|
83
83
|
#
|
|
84
84
|
# [B, A]
|
|
85
85
|
#
|
|
86
|
-
def self.used_modules: () ->
|
|
86
|
+
def self.used_modules: () -> Array[Module]
|
|
87
87
|
|
|
88
88
|
# <!--
|
|
89
89
|
# rdoc-file=eval.c
|
|
@@ -106,7 +106,7 @@ class Module < Object
|
|
|
106
106
|
# using B
|
|
107
107
|
# p Module.used_refinements
|
|
108
108
|
#
|
|
109
|
-
#
|
|
109
|
+
# <em>produces:</em>
|
|
110
110
|
#
|
|
111
111
|
# [#<refinement:Object@B>, #<refinement:Object@A>]
|
|
112
112
|
#
|
|
@@ -114,12 +114,15 @@ class Module < Object
|
|
|
114
114
|
|
|
115
115
|
# <!--
|
|
116
116
|
# rdoc-file=object.c
|
|
117
|
-
# -
|
|
117
|
+
# - self < other -> true, false, or nil
|
|
118
118
|
# -->
|
|
119
|
-
# Returns
|
|
120
|
-
#
|
|
121
|
-
#
|
|
122
|
-
#
|
|
119
|
+
# Returns whether `self` is a subclass of `other`, or `nil` if there is no
|
|
120
|
+
# relationship between the two:
|
|
121
|
+
#
|
|
122
|
+
# Float < Numeric # => true
|
|
123
|
+
# Numeric < Float # => false
|
|
124
|
+
# Float < Float # => false
|
|
125
|
+
# Float < Hash # => nil
|
|
123
126
|
#
|
|
124
127
|
def <: (Module other) -> bool?
|
|
125
128
|
|
|
@@ -135,16 +138,32 @@ class Module < Object
|
|
|
135
138
|
|
|
136
139
|
# <!--
|
|
137
140
|
# rdoc-file=object.c
|
|
138
|
-
# -
|
|
141
|
+
# - self <=> other -> -1, 0, 1, or nil
|
|
139
142
|
# -->
|
|
140
|
-
#
|
|
141
|
-
#
|
|
142
|
-
#
|
|
143
|
+
# Compares `self` and `other`.
|
|
144
|
+
#
|
|
145
|
+
# Returns:
|
|
146
|
+
#
|
|
147
|
+
# * <code>-1</code>, if `self` includes `other`, if or `self` is a subclass of
|
|
148
|
+
# `other`.
|
|
149
|
+
# * `0`, if `self` and `other` are the same.
|
|
150
|
+
# * `1`, if `other` includes `self`, or if `other` is a subclass of `self`.
|
|
151
|
+
# * `nil`, if none of the above is true.
|
|
152
|
+
#
|
|
153
|
+
# Examples:
|
|
143
154
|
#
|
|
144
|
-
#
|
|
145
|
-
#
|
|
155
|
+
# # Class Array includes module Enumerable.
|
|
156
|
+
# Array <=> Enumerable # => -1
|
|
157
|
+
# Enumerable <=> Enumerable # => 0
|
|
158
|
+
# Enumerable <=> Array # => 1
|
|
159
|
+
# # Class File is a subclass of class IO.
|
|
160
|
+
# File <=> IO # => -1
|
|
161
|
+
# File <=> File # => 0
|
|
162
|
+
# IO <=> File # => 1
|
|
163
|
+
# # Class File has no relationship to class String.
|
|
164
|
+
# File <=> String # => nil
|
|
146
165
|
#
|
|
147
|
-
def <=>: (untyped other) ->
|
|
166
|
+
def <=>: (untyped other) -> (-1 | 0 | 1)?
|
|
148
167
|
|
|
149
168
|
# <!--
|
|
150
169
|
# rdoc-file=object.c
|
|
@@ -157,8 +176,8 @@ class Module < Object
|
|
|
157
176
|
# classes to provide class-specific meaning.
|
|
158
177
|
#
|
|
159
178
|
# Unlike #==, the #equal? method should never be overridden by subclasses as it
|
|
160
|
-
# is used to determine object identity (that is,
|
|
161
|
-
# `a` is the same object as `b`):
|
|
179
|
+
# is used to determine object identity (that is, <code>a.equal?(b)</code> if and
|
|
180
|
+
# only if `a` is the same object as `b`):
|
|
162
181
|
#
|
|
163
182
|
# obj = "a"
|
|
164
183
|
# other = obj.dup
|
|
@@ -231,11 +250,11 @@ class Module < Object
|
|
|
231
250
|
# include Mod
|
|
232
251
|
# exit(99)
|
|
233
252
|
#
|
|
234
|
-
#
|
|
253
|
+
# <em>produces:</em>
|
|
235
254
|
#
|
|
236
255
|
# Exiting with code 99
|
|
237
256
|
#
|
|
238
|
-
def alias_method: (interned new_name, interned old_name) ->
|
|
257
|
+
def alias_method: (interned new_name, interned old_name) -> Symbol
|
|
239
258
|
|
|
240
259
|
# <!--
|
|
241
260
|
# rdoc-file=object.c
|
|
@@ -254,7 +273,7 @@ class Module < Object
|
|
|
254
273
|
# Math.ancestors #=> [Math]
|
|
255
274
|
# Enumerable.ancestors #=> [Enumerable]
|
|
256
275
|
#
|
|
257
|
-
def ancestors: () ->
|
|
276
|
+
def ancestors: () -> Array[Module]
|
|
258
277
|
|
|
259
278
|
# <!--
|
|
260
279
|
# rdoc-file=eval.c
|
|
@@ -266,7 +285,7 @@ class Module < Object
|
|
|
266
285
|
# module to *mod* if this module has not already been added to *mod* or one of
|
|
267
286
|
# its ancestors. See also Module#include.
|
|
268
287
|
#
|
|
269
|
-
def append_features: (Module
|
|
288
|
+
private def append_features: (Module mod) -> self
|
|
270
289
|
|
|
271
290
|
# <!--
|
|
272
291
|
# rdoc-file=object.c
|
|
@@ -274,17 +293,17 @@ class Module < Object
|
|
|
274
293
|
# - attr_accessor(string, ...) -> array
|
|
275
294
|
# -->
|
|
276
295
|
# Defines a named attribute for this module, where the name is
|
|
277
|
-
#
|
|
278
|
-
# corresponding access method to read it. Also creates a method called
|
|
279
|
-
# to set the attribute. String arguments are converted to
|
|
280
|
-
# array of defined method names as symbols.
|
|
296
|
+
# <em>symbol.</em>`id2name`, creating an instance variable (<code>@name</code>)
|
|
297
|
+
# and a corresponding access method to read it. Also creates a method called
|
|
298
|
+
# <code>name=</code> to set the attribute. String arguments are converted to
|
|
299
|
+
# symbols. Returns an array of defined method names as symbols.
|
|
281
300
|
#
|
|
282
301
|
# module Mod
|
|
283
302
|
# attr_accessor(:one, :two) #=> [:one, :one=, :two, :two=]
|
|
284
303
|
# end
|
|
285
304
|
# Mod.instance_methods.sort #=> [:one, :one=, :two, :two=]
|
|
286
305
|
#
|
|
287
|
-
def attr_accessor: (*interned
|
|
306
|
+
def attr_accessor: (*interned names) -> Array[Symbol]
|
|
288
307
|
|
|
289
308
|
# <!--
|
|
290
309
|
# rdoc-file=object.c
|
|
@@ -294,11 +313,11 @@ class Module < Object
|
|
|
294
313
|
# - attr(string, ...) -> array
|
|
295
314
|
# -->
|
|
296
315
|
# Creates instance variables and corresponding methods that return the value of
|
|
297
|
-
# each instance variable. Equivalent to calling ```attr
|
|
298
|
-
# in turn. String arguments are converted to symbols. Returns an array of
|
|
316
|
+
# each instance variable. Equivalent to calling ```attr`<em>:name</em>'' on each
|
|
317
|
+
# name in turn. String arguments are converted to symbols. Returns an array of
|
|
299
318
|
# defined method names as symbols.
|
|
300
319
|
#
|
|
301
|
-
def attr_reader: (*interned
|
|
320
|
+
def attr_reader: (*interned names) -> Array[Symbol]
|
|
302
321
|
|
|
303
322
|
# <!--
|
|
304
323
|
# rdoc-file=object.c
|
|
@@ -306,10 +325,10 @@ class Module < Object
|
|
|
306
325
|
# - attr_writer(string, ...) -> array
|
|
307
326
|
# -->
|
|
308
327
|
# Creates an accessor method to allow assignment to the attribute
|
|
309
|
-
# *symbol
|
|
310
|
-
# array of defined method names as symbols.
|
|
328
|
+
# *symbol*<code>.id2name</code>. String arguments are converted to symbols.
|
|
329
|
+
# Returns an array of defined method names as symbols.
|
|
311
330
|
#
|
|
312
|
-
def attr_writer: (*interned
|
|
331
|
+
def attr_writer: (*interned names) -> Array[Symbol]
|
|
313
332
|
|
|
314
333
|
# <!--
|
|
315
334
|
# rdoc-file=load.c
|
|
@@ -328,7 +347,9 @@ class Module < Object
|
|
|
328
347
|
# replaced with *filename*. If *const* is defined but not as autoload, does
|
|
329
348
|
# nothing.
|
|
330
349
|
#
|
|
331
|
-
|
|
350
|
+
# Files that are currently being loaded must not be registered for autoload.
|
|
351
|
+
#
|
|
352
|
+
def autoload: (interned constant, path filename) -> nil
|
|
332
353
|
|
|
333
354
|
# <!--
|
|
334
355
|
# rdoc-file=load.c
|
|
@@ -370,14 +391,13 @@ class Module < Object
|
|
|
370
391
|
# puts Thing.new.hello()
|
|
371
392
|
# Thing.module_eval("invalid code", "dummy", 123)
|
|
372
393
|
#
|
|
373
|
-
#
|
|
394
|
+
# <em>produces:</em>
|
|
374
395
|
#
|
|
375
396
|
# Hello there!
|
|
376
397
|
# dummy:123:in `module_eval': undefined local variable
|
|
377
398
|
# or method `code' for Thing:Class
|
|
378
399
|
#
|
|
379
|
-
|
|
380
|
-
| [U] () { (self m) [self: self] -> U } -> U
|
|
400
|
+
alias class_eval module_eval
|
|
381
401
|
|
|
382
402
|
# <!-- rdoc-file=vm_eval.c -->
|
|
383
403
|
# Evaluates the given block in the context of the class/module. The method
|
|
@@ -392,11 +412,11 @@ class Module < Object
|
|
|
392
412
|
# }
|
|
393
413
|
# puts Thing.new.hello()
|
|
394
414
|
#
|
|
395
|
-
#
|
|
415
|
+
# <em>produces:</em>
|
|
396
416
|
#
|
|
397
417
|
# Hello there!
|
|
398
418
|
#
|
|
399
|
-
|
|
419
|
+
alias class_exec module_exec
|
|
400
420
|
|
|
401
421
|
# <!--
|
|
402
422
|
# rdoc-file=object.c
|
|
@@ -412,7 +432,7 @@ class Module < Object
|
|
|
412
432
|
# Fred.class_variable_defined?(:@@foo) #=> true
|
|
413
433
|
# Fred.class_variable_defined?(:@@bar) #=> false
|
|
414
434
|
#
|
|
415
|
-
def class_variable_defined?: (interned
|
|
435
|
+
def class_variable_defined?: (interned name) -> bool
|
|
416
436
|
|
|
417
437
|
# <!--
|
|
418
438
|
# rdoc-file=object.c
|
|
@@ -420,15 +440,15 @@ class Module < Object
|
|
|
420
440
|
# - mod.class_variable_get(string) -> obj
|
|
421
441
|
# -->
|
|
422
442
|
# Returns the value of the given class variable (or throws a NameError
|
|
423
|
-
# exception). The
|
|
424
|
-
# class variables. String arguments are converted to symbols.
|
|
443
|
+
# exception). The <code>@@</code> part of the variable name should be included
|
|
444
|
+
# for regular class variables. String arguments are converted to symbols.
|
|
425
445
|
#
|
|
426
446
|
# class Fred
|
|
427
447
|
# @@foo = 99
|
|
428
448
|
# end
|
|
429
449
|
# Fred.class_variable_get(:@@foo) #=> 99
|
|
430
450
|
#
|
|
431
|
-
def class_variable_get: (interned
|
|
451
|
+
def class_variable_get: (interned name) -> untyped
|
|
432
452
|
|
|
433
453
|
# <!--
|
|
434
454
|
# rdoc-file=object.c
|
|
@@ -447,7 +467,7 @@ class Module < Object
|
|
|
447
467
|
# Fred.class_variable_set(:@@foo, 101) #=> 101
|
|
448
468
|
# Fred.new.foo #=> 101
|
|
449
469
|
#
|
|
450
|
-
def class_variable_set: (interned
|
|
470
|
+
def class_variable_set: [T] (interned name, T value) -> T
|
|
451
471
|
|
|
452
472
|
# <!--
|
|
453
473
|
# rdoc-file=object.c
|
|
@@ -467,7 +487,7 @@ class Module < Object
|
|
|
467
487
|
# Two.class_variables #=> [:@@var2, :@@var1]
|
|
468
488
|
# Two.class_variables(false) #=> [:@@var2]
|
|
469
489
|
#
|
|
470
|
-
def class_variables: (?boolish inherit) ->
|
|
490
|
+
def class_variables: (?boolish inherit) -> Array[Symbol]
|
|
471
491
|
|
|
472
492
|
# <!--
|
|
473
493
|
# rdoc-file=object.c
|
|
@@ -483,11 +503,36 @@ class Module < Object
|
|
|
483
503
|
# FOO = 1
|
|
484
504
|
# end
|
|
485
505
|
#
|
|
486
|
-
#
|
|
506
|
+
# <em>produces:</em>
|
|
487
507
|
#
|
|
488
508
|
# Added :FOO
|
|
489
509
|
#
|
|
490
|
-
|
|
510
|
+
# If we define a class using the `class` keyword, `const_added` runs before
|
|
511
|
+
# `inherited`:
|
|
512
|
+
#
|
|
513
|
+
# module M
|
|
514
|
+
# def self.const_added(const_name)
|
|
515
|
+
# super
|
|
516
|
+
# p :const_added
|
|
517
|
+
# end
|
|
518
|
+
#
|
|
519
|
+
# parent = Class.new do
|
|
520
|
+
# def self.inherited(subclass)
|
|
521
|
+
# super
|
|
522
|
+
# p :inherited
|
|
523
|
+
# end
|
|
524
|
+
# end
|
|
525
|
+
#
|
|
526
|
+
# class Child < parent
|
|
527
|
+
# end
|
|
528
|
+
# end
|
|
529
|
+
#
|
|
530
|
+
# <em>produces:</em>
|
|
531
|
+
#
|
|
532
|
+
# :const_added
|
|
533
|
+
# :inherited
|
|
534
|
+
#
|
|
535
|
+
private def const_added: (Symbol const_name) -> void
|
|
491
536
|
|
|
492
537
|
# <!--
|
|
493
538
|
# rdoc-file=object.c
|
|
@@ -590,10 +635,11 @@ class Module < Object
|
|
|
590
635
|
#
|
|
591
636
|
# In the next example, when a reference is made to an undefined constant,
|
|
592
637
|
# `const_missing` attempts to load a file whose path is the lowercase version of
|
|
593
|
-
# the constant name (thus class `Fred` is assumed to be in file
|
|
594
|
-
# defined as a side-effect of loading the file, the
|
|
595
|
-
# stored in the constant. This implements an autoload
|
|
596
|
-
# Kernel#autoload and Module#autoload, though it differs in
|
|
638
|
+
# the constant name (thus class `Fred` is assumed to be in file
|
|
639
|
+
# <code>fred.rb</code>). If defined as a side-effect of loading the file, the
|
|
640
|
+
# method returns the value stored in the constant. This implements an autoload
|
|
641
|
+
# feature similar to Kernel#autoload and Module#autoload, though it differs in
|
|
642
|
+
# important ways.
|
|
597
643
|
#
|
|
598
644
|
# def Object.const_missing(name)
|
|
599
645
|
# @looked_for ||= {}
|
|
@@ -605,7 +651,7 @@ class Module < Object
|
|
|
605
651
|
# const_get(name, false)
|
|
606
652
|
# end
|
|
607
653
|
#
|
|
608
|
-
def const_missing: (Symbol
|
|
654
|
+
def const_missing: (Symbol name) -> untyped
|
|
609
655
|
|
|
610
656
|
# <!--
|
|
611
657
|
# rdoc-file=object.c
|
|
@@ -623,7 +669,7 @@ class Module < Object
|
|
|
623
669
|
#
|
|
624
670
|
# Object.const_set('foobar', 42) #=> NameError: wrong constant name foobar
|
|
625
671
|
#
|
|
626
|
-
def const_set: (interned
|
|
672
|
+
def const_set: [T] (interned name, T value) -> T
|
|
627
673
|
|
|
628
674
|
# <!--
|
|
629
675
|
# rdoc-file=object.c
|
|
@@ -635,7 +681,8 @@ class Module < Object
|
|
|
635
681
|
# If the constant is found, but its source location can not be extracted
|
|
636
682
|
# (constant is defined in C code), empty array is returned.
|
|
637
683
|
#
|
|
638
|
-
# *inherit* specifies whether to lookup in
|
|
684
|
+
# *inherit* specifies whether to lookup in <code>mod.ancestors</code> (`true` by
|
|
685
|
+
# default).
|
|
639
686
|
#
|
|
640
687
|
# # test.rb:
|
|
641
688
|
# class A # line 1
|
|
@@ -691,7 +738,7 @@ class Module < Object
|
|
|
691
738
|
#
|
|
692
739
|
# Also see Module#const_defined?.
|
|
693
740
|
#
|
|
694
|
-
def constants: (?boolish inherit) ->
|
|
741
|
+
def constants: (?boolish inherit) -> Array[Symbol]
|
|
695
742
|
|
|
696
743
|
# <!--
|
|
697
744
|
# rdoc-file=proc.c
|
|
@@ -724,7 +771,7 @@ class Module < Object
|
|
|
724
771
|
# a.create_method(:betty) { p self }
|
|
725
772
|
# a.betty
|
|
726
773
|
#
|
|
727
|
-
#
|
|
774
|
+
# <em>produces:</em>
|
|
728
775
|
#
|
|
729
776
|
# In Fred
|
|
730
777
|
# Charge it!
|
|
@@ -751,9 +798,7 @@ class Module < Object
|
|
|
751
798
|
# HTTP::NOT_FOUND
|
|
752
799
|
# # warning: constant HTTP::NOT_FOUND is deprecated
|
|
753
800
|
#
|
|
754
|
-
def deprecate_constant: (*interned) -> self
|
|
755
|
-
|
|
756
|
-
def eql?: (untyped other) -> bool
|
|
801
|
+
def deprecate_constant: (*interned names) -> self
|
|
757
802
|
|
|
758
803
|
def equal?: (untyped other) -> bool
|
|
759
804
|
|
|
@@ -778,12 +823,12 @@ class Module < Object
|
|
|
778
823
|
# (s = Array.new).extend Picky # Call Object.extend
|
|
779
824
|
# (s = "quick brown fox").extend Picky
|
|
780
825
|
#
|
|
781
|
-
#
|
|
826
|
+
# <em>produces:</em>
|
|
782
827
|
#
|
|
783
828
|
# Picky added to Array
|
|
784
829
|
# Can't add Picky to a String
|
|
785
830
|
#
|
|
786
|
-
def extend_object: (
|
|
831
|
+
private def extend_object: [T] (T object) -> T
|
|
787
832
|
|
|
788
833
|
# <!--
|
|
789
834
|
# rdoc-file=object.c
|
|
@@ -801,7 +846,7 @@ class Module < Object
|
|
|
801
846
|
# end
|
|
802
847
|
# # => prints "A extended in Enumerable"
|
|
803
848
|
#
|
|
804
|
-
def extended: (
|
|
849
|
+
private def extended: (untyped othermod) -> void
|
|
805
850
|
|
|
806
851
|
# <!--
|
|
807
852
|
# rdoc-file=object.c
|
|
@@ -819,7 +864,7 @@ class Module < Object
|
|
|
819
864
|
# -->
|
|
820
865
|
# Invokes Module.append_features on each parameter in reverse order.
|
|
821
866
|
#
|
|
822
|
-
def include: (Module, *Module
|
|
867
|
+
def include: (Module module, *Module additional_modules) -> self
|
|
823
868
|
|
|
824
869
|
# <!--
|
|
825
870
|
# rdoc-file=object.c
|
|
@@ -846,8 +891,8 @@ class Module < Object
|
|
|
846
891
|
# - included(othermod)
|
|
847
892
|
# -->
|
|
848
893
|
# Callback invoked whenever the receiver is included in another module or class.
|
|
849
|
-
# This should be used in preference to
|
|
850
|
-
# wants to perform some action when a module is included in another.
|
|
894
|
+
# This should be used in preference to <code>Module.append_features</code> if
|
|
895
|
+
# your code wants to perform some action when a module is included in another.
|
|
851
896
|
#
|
|
852
897
|
# module A
|
|
853
898
|
# def A.included(mod)
|
|
@@ -859,7 +904,7 @@ class Module < Object
|
|
|
859
904
|
# end
|
|
860
905
|
# # => prints "A included in Enumerable"
|
|
861
906
|
#
|
|
862
|
-
def included: (Module othermod) ->
|
|
907
|
+
private def included: (Module othermod) -> void
|
|
863
908
|
|
|
864
909
|
# <!--
|
|
865
910
|
# rdoc-file=object.c
|
|
@@ -882,7 +927,7 @@ class Module < Object
|
|
|
882
927
|
# Mixin.included_modules #=> [Sub]
|
|
883
928
|
# Outer.included_modules #=> [Sub, Mixin]
|
|
884
929
|
#
|
|
885
|
-
def included_modules: () ->
|
|
930
|
+
def included_modules: () -> Array[Module]
|
|
886
931
|
|
|
887
932
|
# <!--
|
|
888
933
|
# rdoc-file=object.c
|
|
@@ -909,8 +954,9 @@ class Module < Object
|
|
|
909
954
|
# Assign the module to a constant (name starting uppercase) if you want to treat
|
|
910
955
|
# it like a regular module.
|
|
911
956
|
#
|
|
912
|
-
def initialize: () -> void
|
|
913
|
-
|
|
957
|
+
def initialize: () ?{ (Module mod) [self: self] -> void } -> void
|
|
958
|
+
|
|
959
|
+
def initialize_clone: (Module source, ?freeze: bool?) -> void
|
|
914
960
|
|
|
915
961
|
# <!--
|
|
916
962
|
# rdoc-file=proc.c
|
|
@@ -937,11 +983,11 @@ class Module < Object
|
|
|
937
983
|
# interpreter = Interpreter.new
|
|
938
984
|
# interpreter.interpret('dave')
|
|
939
985
|
#
|
|
940
|
-
#
|
|
986
|
+
# <em>produces:</em>
|
|
941
987
|
#
|
|
942
988
|
# Hello there, Dave!
|
|
943
989
|
#
|
|
944
|
-
def instance_method: (interned
|
|
990
|
+
def instance_method: (interned name) -> UnboundMethod
|
|
945
991
|
|
|
946
992
|
# <!--
|
|
947
993
|
# rdoc-file=object.c
|
|
@@ -978,7 +1024,7 @@ class Module < Object
|
|
|
978
1024
|
# end
|
|
979
1025
|
# C.instance_methods(false).sort #=> [:method2, :method3, :method4]
|
|
980
1026
|
#
|
|
981
|
-
def instance_methods: (?boolish include_super) ->
|
|
1027
|
+
def instance_methods: (?boolish include_super) -> Array[Symbol]
|
|
982
1028
|
|
|
983
1029
|
# <!--
|
|
984
1030
|
# rdoc-file=object.c
|
|
@@ -994,11 +1040,11 @@ class Module < Object
|
|
|
994
1040
|
# def some_instance_method() end
|
|
995
1041
|
# end
|
|
996
1042
|
#
|
|
997
|
-
#
|
|
1043
|
+
# <em>produces:</em>
|
|
998
1044
|
#
|
|
999
1045
|
# Adding :some_instance_method
|
|
1000
1046
|
#
|
|
1001
|
-
def method_added: (Symbol
|
|
1047
|
+
private def method_added: (Symbol method_name) -> void
|
|
1002
1048
|
|
|
1003
1049
|
# <!--
|
|
1004
1050
|
# rdoc-file=vm_method.c
|
|
@@ -1055,11 +1101,36 @@ class Module < Object
|
|
|
1055
1101
|
# remove_method :some_instance_method
|
|
1056
1102
|
# end
|
|
1057
1103
|
#
|
|
1058
|
-
#
|
|
1104
|
+
# <em>produces:</em>
|
|
1059
1105
|
#
|
|
1060
1106
|
# Removing :some_instance_method
|
|
1061
1107
|
#
|
|
1062
|
-
def method_removed: (Symbol method_name) ->
|
|
1108
|
+
private def method_removed: (Symbol method_name) -> void
|
|
1109
|
+
|
|
1110
|
+
# <!--
|
|
1111
|
+
# rdoc-file=object.c
|
|
1112
|
+
# - method_undefined(method_name)
|
|
1113
|
+
# -->
|
|
1114
|
+
# Invoked as a callback whenever an instance method is undefined from the
|
|
1115
|
+
# receiver.
|
|
1116
|
+
#
|
|
1117
|
+
# module Chatty
|
|
1118
|
+
# def self.method_undefined(method_name)
|
|
1119
|
+
# puts "Undefining #{method_name.inspect}"
|
|
1120
|
+
# end
|
|
1121
|
+
# def self.some_class_method() end
|
|
1122
|
+
# def some_instance_method() end
|
|
1123
|
+
# class << self
|
|
1124
|
+
# undef_method :some_class_method
|
|
1125
|
+
# end
|
|
1126
|
+
# undef_method :some_instance_method
|
|
1127
|
+
# end
|
|
1128
|
+
#
|
|
1129
|
+
# <em>produces:</em>
|
|
1130
|
+
#
|
|
1131
|
+
# Undefining :some_instance_method
|
|
1132
|
+
#
|
|
1133
|
+
private def method_undefined: (Symbol method_name) -> void
|
|
1063
1134
|
|
|
1064
1135
|
# <!--
|
|
1065
1136
|
# rdoc-file=vm_eval.c
|
|
@@ -1081,14 +1152,14 @@ class Module < Object
|
|
|
1081
1152
|
# puts Thing.new.hello()
|
|
1082
1153
|
# Thing.module_eval("invalid code", "dummy", 123)
|
|
1083
1154
|
#
|
|
1084
|
-
#
|
|
1155
|
+
# <em>produces:</em>
|
|
1085
1156
|
#
|
|
1086
1157
|
# Hello there!
|
|
1087
1158
|
# dummy:123:in `module_eval': undefined local variable
|
|
1088
1159
|
# or method `code' for Thing:Class
|
|
1089
1160
|
#
|
|
1090
|
-
def module_eval: (
|
|
1091
|
-
| [U] () { (self
|
|
1161
|
+
def module_eval: (string code, ?string? filename, ?int lineno) -> untyped
|
|
1162
|
+
| [U] () { (self mod) [self: self] -> U } -> U
|
|
1092
1163
|
|
|
1093
1164
|
# <!--
|
|
1094
1165
|
# rdoc-file=vm_eval.c
|
|
@@ -1107,7 +1178,7 @@ class Module < Object
|
|
|
1107
1178
|
# }
|
|
1108
1179
|
# puts Thing.new.hello()
|
|
1109
1180
|
#
|
|
1110
|
-
#
|
|
1181
|
+
# <em>produces:</em>
|
|
1111
1182
|
#
|
|
1112
1183
|
# Hello there!
|
|
1113
1184
|
#
|
|
@@ -1152,11 +1223,13 @@ class Module < Object
|
|
|
1152
1223
|
# Mod.one #=> "This is one"
|
|
1153
1224
|
# c.call_one #=> "This is the new one"
|
|
1154
1225
|
#
|
|
1155
|
-
def module_function: () -> nil
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1226
|
+
private def module_function: () -> nil
|
|
1227
|
+
| (Symbol method_name) -> Symbol
|
|
1228
|
+
| [T < _ToStr] (T method_name) -> T
|
|
1229
|
+
| (interned method_name) -> interned
|
|
1230
|
+
| (Symbol, Symbol, *Symbol method_names) -> Array[Symbol]
|
|
1231
|
+
| [T < _ToStr] (T, T, *T method_names) -> Array[T]
|
|
1232
|
+
| (interned, interned, *interned method_names) -> Array[interned]
|
|
1160
1233
|
|
|
1161
1234
|
# <!--
|
|
1162
1235
|
# rdoc-file=object.c
|
|
@@ -1172,7 +1245,7 @@ class Module < Object
|
|
|
1172
1245
|
# -->
|
|
1173
1246
|
# Invokes Module.prepend_features on each parameter in reverse order.
|
|
1174
1247
|
#
|
|
1175
|
-
def prepend: (Module, *Module
|
|
1248
|
+
def prepend: (Module module, *Module additional_modules) -> self
|
|
1176
1249
|
|
|
1177
1250
|
# <!--
|
|
1178
1251
|
# rdoc-file=eval.c
|
|
@@ -1184,7 +1257,7 @@ class Module < Object
|
|
|
1184
1257
|
# this module to *mod* if this module has not already been added to *mod* or one
|
|
1185
1258
|
# of its ancestors. See also Module#prepend.
|
|
1186
1259
|
#
|
|
1187
|
-
def prepend_features: (Module
|
|
1260
|
+
private def prepend_features: (Module mod) -> self
|
|
1188
1261
|
|
|
1189
1262
|
# <!--
|
|
1190
1263
|
# rdoc-file=object.c
|
|
@@ -1202,7 +1275,7 @@ class Module < Object
|
|
|
1202
1275
|
# end
|
|
1203
1276
|
# # => prints "A prepended to Enumerable"
|
|
1204
1277
|
#
|
|
1205
|
-
def prepended: (Module othermod) ->
|
|
1278
|
+
private def prepended: (Module othermod) -> void
|
|
1206
1279
|
|
|
1207
1280
|
# <!--
|
|
1208
1281
|
# rdoc-file=vm_method.c
|
|
@@ -1227,14 +1300,18 @@ class Module < Object
|
|
|
1227
1300
|
# end
|
|
1228
1301
|
# Mod.private_instance_methods #=> [:a, :c]
|
|
1229
1302
|
#
|
|
1230
|
-
# Note that to show a private method on RDoc, use
|
|
1303
|
+
# Note that to show a private method on RDoc, use <code>:doc:</code>.
|
|
1231
1304
|
#
|
|
1232
|
-
def private: () -> nil
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1305
|
+
private def private: () -> nil
|
|
1306
|
+
| (Symbol method_name) -> Symbol
|
|
1307
|
+
| [T < _ToStr] (T method_name) -> T
|
|
1308
|
+
| (interned method_name) -> interned
|
|
1309
|
+
| (Symbol, Symbol, *Symbol method_names) -> Array[Symbol]
|
|
1310
|
+
| [T < _ToStr] (T, T, *T method_names) -> Array[T]
|
|
1311
|
+
| (interned, interned, *interned method_names) -> Array[interned]
|
|
1312
|
+
| (Array[Symbol] method_names) -> Array[Symbol]
|
|
1313
|
+
| [T < _ToStr] (Array[T] method_names) -> Array[T]
|
|
1314
|
+
| (Array[interned] method_names) -> Array[interned]
|
|
1238
1315
|
|
|
1239
1316
|
# <!--
|
|
1240
1317
|
# rdoc-file=vm_method.c
|
|
@@ -1256,8 +1333,8 @@ class Module < Object
|
|
|
1256
1333
|
# end
|
|
1257
1334
|
# end
|
|
1258
1335
|
#
|
|
1259
|
-
def private_class_method: (*interned
|
|
1260
|
-
| (Array[interned]
|
|
1336
|
+
def private_class_method: (*interned method_names) -> self
|
|
1337
|
+
| (Array[interned] method_names) -> self
|
|
1261
1338
|
|
|
1262
1339
|
# <!--
|
|
1263
1340
|
# rdoc-file=object.c
|
|
@@ -1265,7 +1342,7 @@ class Module < Object
|
|
|
1265
1342
|
# -->
|
|
1266
1343
|
# Makes a list of existing constants private.
|
|
1267
1344
|
#
|
|
1268
|
-
def private_constant: (*interned
|
|
1345
|
+
def private_constant: (*interned names) -> self
|
|
1269
1346
|
|
|
1270
1347
|
# <!--
|
|
1271
1348
|
# rdoc-file=object.c
|
|
@@ -1282,7 +1359,7 @@ class Module < Object
|
|
|
1282
1359
|
# Mod.instance_methods #=> [:method2]
|
|
1283
1360
|
# Mod.private_instance_methods #=> [:method1]
|
|
1284
1361
|
#
|
|
1285
|
-
def private_instance_methods: (?boolish include_super) ->
|
|
1362
|
+
def private_instance_methods: (?boolish include_super) -> Array[Symbol]
|
|
1286
1363
|
|
|
1287
1364
|
# <!--
|
|
1288
1365
|
# rdoc-file=vm_method.c
|
|
@@ -1321,28 +1398,65 @@ class Module < Object
|
|
|
1321
1398
|
# - protected(method_name, method_name, ...) -> array
|
|
1322
1399
|
# - protected(array) -> array
|
|
1323
1400
|
# -->
|
|
1324
|
-
#
|
|
1325
|
-
#
|
|
1326
|
-
#
|
|
1327
|
-
#
|
|
1328
|
-
#
|
|
1329
|
-
#
|
|
1401
|
+
# Sets the visibility of a section or of a list of method names as protected.
|
|
1402
|
+
# Accepts no arguments, a splat of method names (symbols or strings) or an array
|
|
1403
|
+
# of method names. Returns the arguments that it received.
|
|
1404
|
+
#
|
|
1405
|
+
# ## Important difference between protected in other languages
|
|
1406
|
+
#
|
|
1407
|
+
# Protected methods in Ruby are different from other languages such as Java,
|
|
1408
|
+
# where methods are marked as protected to give access to subclasses. In Ruby,
|
|
1409
|
+
# subclasses **already have access to all methods defined in the parent class**,
|
|
1410
|
+
# even private ones.
|
|
1411
|
+
#
|
|
1412
|
+
# Marking a method as protected allows **different objects of the same class**
|
|
1413
|
+
# to call it.
|
|
1414
|
+
#
|
|
1415
|
+
# One use case is for comparison methods, such as <code>==</code>, if we want to
|
|
1416
|
+
# expose a method for comparison between objects of the same class without
|
|
1417
|
+
# making the method public to objects of other classes.
|
|
1418
|
+
#
|
|
1419
|
+
# ## Performance considerations
|
|
1420
|
+
#
|
|
1421
|
+
# Protected methods are slower than others because they can't use inline cache.
|
|
1330
1422
|
#
|
|
1331
|
-
#
|
|
1332
|
-
# context is the same as the method. (method definition or instance_eval). This
|
|
1333
|
-
# behavior is different from Java's protected method. Usually `private` should
|
|
1334
|
-
# be used.
|
|
1423
|
+
# ## Example
|
|
1335
1424
|
#
|
|
1336
|
-
#
|
|
1425
|
+
# class Account
|
|
1426
|
+
# # Mark balance as protected, so that we can compare between accounts
|
|
1427
|
+
# # without making it public.
|
|
1428
|
+
# attr_reader :balance
|
|
1429
|
+
# protected :balance
|
|
1337
1430
|
#
|
|
1338
|
-
#
|
|
1431
|
+
# def initialize(balance)
|
|
1432
|
+
# @balance = balance
|
|
1433
|
+
# end
|
|
1434
|
+
#
|
|
1435
|
+
# def >(other)
|
|
1436
|
+
# # The invocation to `other.balance` is allowed because `other` is a
|
|
1437
|
+
# # different object of the same class (Account).
|
|
1438
|
+
# balance > other.balance
|
|
1439
|
+
# end
|
|
1440
|
+
# end
|
|
1441
|
+
#
|
|
1442
|
+
# account1 = Account.new(100)
|
|
1443
|
+
# account2 = Account.new(50)
|
|
1339
1444
|
#
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1445
|
+
# account1 > account2 # => true (works)
|
|
1446
|
+
# account1.balance # => NoMethodError (fails because balance is not public)
|
|
1447
|
+
#
|
|
1448
|
+
# To show a private method on RDoc, use <code>:doc:</code> instead of this.
|
|
1449
|
+
#
|
|
1450
|
+
private def protected: () -> nil
|
|
1451
|
+
| (Symbol method_name) -> Symbol
|
|
1452
|
+
| [T < _ToStr] (T method_name) -> T
|
|
1453
|
+
| (interned method_name) -> interned
|
|
1454
|
+
| (Symbol, Symbol, *Symbol method_names) -> Array[Symbol]
|
|
1455
|
+
| [T < _ToStr] (T, T, *T method_names) -> Array[T]
|
|
1456
|
+
| (interned, interned, *interned method_names) -> Array[interned]
|
|
1457
|
+
| (Array[Symbol] method_names) -> Array[Symbol]
|
|
1458
|
+
| [T < _ToStr] (Array[T] method_names) -> Array[T]
|
|
1459
|
+
| (Array[interned] method_names) -> Array[interned]
|
|
1346
1460
|
|
|
1347
1461
|
# <!--
|
|
1348
1462
|
# rdoc-file=object.c
|
|
@@ -1351,7 +1465,7 @@ class Module < Object
|
|
|
1351
1465
|
# Returns a list of the protected instance methods defined in *mod*. If the
|
|
1352
1466
|
# optional parameter is `false`, the methods of any ancestors are not included.
|
|
1353
1467
|
#
|
|
1354
|
-
def protected_instance_methods: (?boolish include_super) ->
|
|
1468
|
+
def protected_instance_methods: (?boolish include_super) -> Array[Symbol]
|
|
1355
1469
|
|
|
1356
1470
|
# <!--
|
|
1357
1471
|
# rdoc-file=vm_method.c
|
|
@@ -1397,12 +1511,16 @@ class Module < Object
|
|
|
1397
1511
|
# returned. If no argument is passed, nil is returned. If multiple arguments are
|
|
1398
1512
|
# passed, the arguments are returned as an array.
|
|
1399
1513
|
#
|
|
1400
|
-
def public: () -> nil
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1514
|
+
private def public: () -> nil
|
|
1515
|
+
| (Symbol method_name) -> Symbol
|
|
1516
|
+
| [T < _ToStr] (T method_name) -> T
|
|
1517
|
+
| (interned method_name) -> interned
|
|
1518
|
+
| (Symbol, Symbol, *Symbol method_names) -> Array[Symbol]
|
|
1519
|
+
| [T < _ToStr] (T, T, *T method_names) -> Array[T]
|
|
1520
|
+
| (interned, interned, *interned method_names) -> Array[interned]
|
|
1521
|
+
| (Array[Symbol] method_names) -> Array[Symbol]
|
|
1522
|
+
| [T < _ToStr] (Array[T] method_names) -> Array[T]
|
|
1523
|
+
| (Array[interned] method_names) -> Array[interned]
|
|
1406
1524
|
|
|
1407
1525
|
# <!--
|
|
1408
1526
|
# rdoc-file=vm_method.c
|
|
@@ -1415,8 +1533,8 @@ class Module < Object
|
|
|
1415
1533
|
# String arguments are converted to symbols. An Array of Symbols and/or Strings
|
|
1416
1534
|
# is also accepted.
|
|
1417
1535
|
#
|
|
1418
|
-
def public_class_method: (*interned
|
|
1419
|
-
| (Array[interned]
|
|
1536
|
+
def public_class_method: (*interned method_names) -> self
|
|
1537
|
+
| (Array[interned] method_names) -> self
|
|
1420
1538
|
|
|
1421
1539
|
# <!--
|
|
1422
1540
|
# rdoc-file=object.c
|
|
@@ -1424,7 +1542,7 @@ class Module < Object
|
|
|
1424
1542
|
# -->
|
|
1425
1543
|
# Makes a list of existing constants public.
|
|
1426
1544
|
#
|
|
1427
|
-
def public_constant: (*interned
|
|
1545
|
+
def public_constant: (*interned names) -> self
|
|
1428
1546
|
|
|
1429
1547
|
# <!--
|
|
1430
1548
|
# rdoc-file=proc.c
|
|
@@ -1441,7 +1559,7 @@ class Module < Object
|
|
|
1441
1559
|
# Returns a list of the public instance methods defined in *mod*. If the
|
|
1442
1560
|
# optional parameter is `false`, the methods of any ancestors are not included.
|
|
1443
1561
|
#
|
|
1444
|
-
def public_instance_methods: (?boolish include_super) ->
|
|
1562
|
+
def public_instance_methods: (?boolish include_super) -> Array[Symbol]
|
|
1445
1563
|
|
|
1446
1564
|
# <!--
|
|
1447
1565
|
# rdoc-file=vm_method.c
|
|
@@ -1481,7 +1599,7 @@ class Module < Object
|
|
|
1481
1599
|
#
|
|
1482
1600
|
# Returns a module, where refined methods are defined.
|
|
1483
1601
|
#
|
|
1484
|
-
def refine: (Module mod) { () [self: Refinement] -> void } -> Refinement
|
|
1602
|
+
private def refine: (Module mod) { () [self: Refinement] -> void } -> Refinement
|
|
1485
1603
|
|
|
1486
1604
|
# <!--
|
|
1487
1605
|
# rdoc-file=eval.c
|
|
@@ -1499,7 +1617,7 @@ class Module < Object
|
|
|
1499
1617
|
#
|
|
1500
1618
|
# p A.refinements
|
|
1501
1619
|
#
|
|
1502
|
-
#
|
|
1620
|
+
# <em>produces:</em>
|
|
1503
1621
|
#
|
|
1504
1622
|
# [#<refinement:Integer@A>, #<refinement:String@A>]
|
|
1505
1623
|
#
|
|
@@ -1518,12 +1636,12 @@ class Module < Object
|
|
|
1518
1636
|
# p(defined? @@var)
|
|
1519
1637
|
# end
|
|
1520
1638
|
#
|
|
1521
|
-
#
|
|
1639
|
+
# <em>produces:</em>
|
|
1522
1640
|
#
|
|
1523
1641
|
# 99
|
|
1524
1642
|
# nil
|
|
1525
1643
|
#
|
|
1526
|
-
def remove_class_variable: (interned
|
|
1644
|
+
def remove_class_variable: (interned name) -> untyped
|
|
1527
1645
|
|
|
1528
1646
|
# <!--
|
|
1529
1647
|
# rdoc-file=object.c
|
|
@@ -1533,7 +1651,7 @@ class Module < Object
|
|
|
1533
1651
|
# previous value. If that constant referred to a module, this will not change
|
|
1534
1652
|
# that module's name and can lead to confusion.
|
|
1535
1653
|
#
|
|
1536
|
-
def remove_const: (interned
|
|
1654
|
+
private def remove_const: (interned name) -> untyped
|
|
1537
1655
|
|
|
1538
1656
|
# <!--
|
|
1539
1657
|
# rdoc-file=vm_method.c
|
|
@@ -1543,7 +1661,44 @@ class Module < Object
|
|
|
1543
1661
|
# Removes the method identified by *symbol* from the current class. For an
|
|
1544
1662
|
# example, see Module#undef_method. String arguments are converted to symbols.
|
|
1545
1663
|
#
|
|
1546
|
-
def remove_method: (*interned
|
|
1664
|
+
def remove_method: (*interned method_names) -> self
|
|
1665
|
+
|
|
1666
|
+
# <!--
|
|
1667
|
+
# rdoc-file=vm_method.c
|
|
1668
|
+
# - ruby2_keywords(method_name, ...) -> nil
|
|
1669
|
+
# -->
|
|
1670
|
+
# For the given method names, marks the method as passing keywords through a
|
|
1671
|
+
# normal argument splat. This should only be called on methods that accept an
|
|
1672
|
+
# argument splat (<code>*args</code>) but not explicit keywords or a keyword
|
|
1673
|
+
# splat. It marks the method such that if the method is called with keyword
|
|
1674
|
+
# arguments, the final hash argument is marked with a special flag such that if
|
|
1675
|
+
# it is the final element of a normal argument splat to another method call, and
|
|
1676
|
+
# that method call does not include explicit keywords or a keyword splat, the
|
|
1677
|
+
# final element is interpreted as keywords. In other words, keywords will be
|
|
1678
|
+
# passed through the method to other methods.
|
|
1679
|
+
#
|
|
1680
|
+
# This should only be used for methods that delegate keywords to another method,
|
|
1681
|
+
# and only for backwards compatibility with Ruby versions before 3.0. See
|
|
1682
|
+
# https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyw
|
|
1683
|
+
# ord-arguments-in-ruby-3-0/ for details on why `ruby2_keywords` exists and when
|
|
1684
|
+
# and how to use it.
|
|
1685
|
+
#
|
|
1686
|
+
# This method will probably be removed at some point, as it exists only for
|
|
1687
|
+
# backwards compatibility. As it does not exist in Ruby versions before 2.7,
|
|
1688
|
+
# check that the module responds to this method before calling it:
|
|
1689
|
+
#
|
|
1690
|
+
# module Mod
|
|
1691
|
+
# def foo(meth, *args, &block)
|
|
1692
|
+
# send(:"do_#{meth}", *args, &block)
|
|
1693
|
+
# end
|
|
1694
|
+
# ruby2_keywords(:foo) if respond_to?(:ruby2_keywords, true)
|
|
1695
|
+
# end
|
|
1696
|
+
#
|
|
1697
|
+
# However, be aware that if the `ruby2_keywords` method is removed, the behavior
|
|
1698
|
+
# of the `foo` method using the above approach will change so that the method
|
|
1699
|
+
# does not pass through keywords.
|
|
1700
|
+
#
|
|
1701
|
+
private def ruby2_keywords: (interned method_name, *interned more_method_names) -> nil
|
|
1547
1702
|
|
|
1548
1703
|
# <!--
|
|
1549
1704
|
# rdoc-file=object.c
|
|
@@ -1578,7 +1733,7 @@ class Module < Object
|
|
|
1578
1733
|
# m.name #=> nil
|
|
1579
1734
|
#
|
|
1580
1735
|
# c = Class.new
|
|
1581
|
-
# c.set_temporary_name("MyClass(with description)")
|
|
1736
|
+
# c.set_temporary_name("MyClass(with description)") # => MyClass(with description)
|
|
1582
1737
|
#
|
|
1583
1738
|
# c.new # => #<MyClass(with description):0x0....>
|
|
1584
1739
|
#
|
|
@@ -1592,7 +1747,7 @@ class Module < Object
|
|
|
1592
1747
|
# C::M.name #=> "C::M"
|
|
1593
1748
|
# c.new # => #<C:0x0....>
|
|
1594
1749
|
#
|
|
1595
|
-
def set_temporary_name: (string?) -> self
|
|
1750
|
+
def set_temporary_name: (string? name) -> self
|
|
1596
1751
|
|
|
1597
1752
|
# <!--
|
|
1598
1753
|
# rdoc-file=object.c
|
|
@@ -1652,7 +1807,7 @@ class Module < Object
|
|
|
1652
1807
|
# end
|
|
1653
1808
|
# c.hello
|
|
1654
1809
|
#
|
|
1655
|
-
#
|
|
1810
|
+
# <em>produces:</em>
|
|
1656
1811
|
#
|
|
1657
1812
|
# In child
|
|
1658
1813
|
# In parent
|
|
@@ -1676,14 +1831,14 @@ class Module < Object
|
|
|
1676
1831
|
# Import class refinements from *module* into the current class or module
|
|
1677
1832
|
# definition.
|
|
1678
1833
|
#
|
|
1679
|
-
def using: (Module
|
|
1834
|
+
private def using: (Module mod) -> self
|
|
1680
1835
|
|
|
1681
1836
|
# <!-- rdoc-file=object.c -->
|
|
1682
1837
|
# Returns a string representing this module or class. For basic classes and
|
|
1683
1838
|
# modules, this is the name. For singletons, we show information on the thing
|
|
1684
1839
|
# we're attached to as well.
|
|
1685
1840
|
#
|
|
1686
|
-
|
|
1841
|
+
alias inspect to_s
|
|
1687
1842
|
|
|
1688
1843
|
# <!--
|
|
1689
1844
|
# rdoc-file=object.c
|
|
@@ -1692,13 +1847,10 @@ class Module < Object
|
|
|
1692
1847
|
# - attr(name, false) -> array
|
|
1693
1848
|
# -->
|
|
1694
1849
|
# The first form is equivalent to #attr_reader. The second form is equivalent to
|
|
1695
|
-
#
|
|
1696
|
-
#
|
|
1697
|
-
# as symbols.
|
|
1850
|
+
# <code>attr_accessor(name)</code> but deprecated. The last form is equivalent
|
|
1851
|
+
# to <code>attr_reader(name)</code> but deprecated. Returns an array of defined
|
|
1852
|
+
# method names as symbols.
|
|
1698
1853
|
#
|
|
1699
|
-
def attr: (
|
|
1700
|
-
|
|
1701
|
-
# A previous incarnation of `interned` for backward-compatibility (see #1499)
|
|
1702
|
-
%a{deprecated: Use `interned`}
|
|
1703
|
-
type id = interned
|
|
1854
|
+
def attr: %a{deprecated} (interned name, bool create_writer) -> Array[Symbol]
|
|
1855
|
+
| (*interned names) -> Array[Symbol]
|
|
1704
1856
|
end
|