steep 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/exe/rbs +1 -1
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +55 -55
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/langserver.rb +6 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/project/completion_provider.rb +5 -11
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +42 -46
- data/lib/steep/project/hover_content.rb +11 -5
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +10 -4
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +8 -8
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +987 -711
- data/lib/steep/type_inference/constant_env.rb +1 -1
- data/lib/steep/type_inference/context.rb +7 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +79 -22
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +6 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +1 -1
- data/vendor/ruby-signature/.gitignore +2 -2
- data/vendor/ruby-signature/README.md +2 -2
- data/vendor/ruby-signature/Rakefile +2 -2
- data/vendor/ruby-signature/bin/annotate-with-rdoc +14 -13
- data/vendor/ruby-signature/bin/console +1 -1
- data/vendor/ruby-signature/bin/sort +7 -6
- data/vendor/ruby-signature/bin/test_runner.rb +0 -1
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +1 -1
- data/vendor/ruby-signature/docs/sigs.md +3 -3
- data/vendor/ruby-signature/docs/stdlib.md +1 -1
- data/vendor/ruby-signature/docs/syntax.md +9 -9
- data/vendor/ruby-signature/exe/rbs +5 -1
- data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +27 -0
- data/vendor/ruby-signature/lib/rbs/ast/comment.rb +27 -0
- data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +395 -0
- data/vendor/ruby-signature/lib/rbs/ast/members.rb +362 -0
- data/vendor/ruby-signature/lib/rbs/buffer.rb +50 -0
- data/vendor/ruby-signature/lib/rbs/builtin_names.rb +55 -0
- data/vendor/ruby-signature/lib/rbs/cli.rb +558 -0
- data/vendor/ruby-signature/lib/rbs/constant.rb +26 -0
- data/vendor/ruby-signature/lib/rbs/constant_table.rb +150 -0
- data/vendor/ruby-signature/lib/rbs/definition.rb +170 -0
- data/vendor/ruby-signature/lib/rbs/definition_builder.rb +919 -0
- data/vendor/ruby-signature/lib/rbs/environment.rb +281 -0
- data/vendor/ruby-signature/lib/rbs/environment_loader.rb +136 -0
- data/vendor/ruby-signature/lib/rbs/environment_walker.rb +124 -0
- data/vendor/ruby-signature/lib/rbs/errors.rb +187 -0
- data/vendor/ruby-signature/lib/rbs/location.rb +102 -0
- data/vendor/ruby-signature/lib/rbs/method_type.rb +123 -0
- data/vendor/ruby-signature/lib/rbs/namespace.rb +91 -0
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.rb +21 -23
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.y +18 -18
- data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +553 -0
- data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +587 -0
- data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +381 -0
- data/vendor/ruby-signature/lib/rbs/substitution.rb +46 -0
- data/vendor/ruby-signature/lib/rbs/test/errors.rb +61 -0
- data/vendor/ruby-signature/lib/rbs/test/hook.rb +294 -0
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/test/setup.rb +7 -7
- data/vendor/ruby-signature/lib/rbs/test/spy.rb +325 -0
- data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +183 -0
- data/vendor/ruby-signature/lib/rbs/test/type_check.rb +254 -0
- data/vendor/ruby-signature/lib/rbs/test.rb +26 -0
- data/vendor/ruby-signature/lib/rbs/type_name.rb +70 -0
- data/vendor/ruby-signature/lib/rbs/types.rb +936 -0
- data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +138 -0
- data/vendor/ruby-signature/lib/rbs/vendorer.rb +47 -0
- data/vendor/ruby-signature/lib/rbs/version.rb +3 -0
- data/vendor/ruby-signature/lib/rbs/writer.rb +269 -0
- data/vendor/ruby-signature/lib/rbs.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +4 -61
- data/vendor/ruby-signature/{ruby-signature.gemspec → rbs.gemspec} +4 -4
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +58 -1
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +69 -13
- data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +372 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +9 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +1 -7
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +2 -1
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +3 -2
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +902 -302
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +190 -68
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +3 -6
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +6 -4
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +146 -120
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +310 -7
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +11 -8
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +959 -103
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +3 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +981 -108
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +215 -41
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +47 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +9 -2
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +282 -11
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +11 -13
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +25 -29
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +1 -1
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +875 -567
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +243 -44
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +103 -109
- data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +62 -0
- data/vendor/ruby-signature/stdlib/csv/csv.rbs +773 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +375 -1
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -4
- data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +247 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +1088 -16
- data/vendor/ruby-signature/stdlib/set/set.rbs +251 -27
- metadata +49 -44
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
@@ -1,126 +1,495 @@
|
|
1
|
-
# A
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# Mod.instance_methods #=> [:meth]
|
22
|
-
# ```
|
1
|
+
# A Module is a collection of methods and constants. The methods in a module may
|
2
|
+
# be instance methods or module methods. Instance methods appear as methods in a
|
3
|
+
# class when the module is included, module methods do not. Conversely, module
|
4
|
+
# methods may be called without creating an encapsulating object, while instance
|
5
|
+
# methods may not. (See Module#module_function.)
|
6
|
+
#
|
7
|
+
# In the descriptions that follow, the parameter *sym* refers to a symbol, which
|
8
|
+
# is either a quoted string or a Symbol (such as `:name`).
|
9
|
+
#
|
10
|
+
# module Mod
|
11
|
+
# include Math
|
12
|
+
# CONST = 1
|
13
|
+
# def meth
|
14
|
+
# # ...
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# Mod.class #=> Module
|
18
|
+
# Mod.constants #=> [:CONST, :PI, :E]
|
19
|
+
# Mod.instance_methods #=> [:meth]
|
20
|
+
#
|
23
21
|
class Module < Object
|
24
|
-
# In the first form, returns an array of the names of all constants
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# The second form calls the instance method `constants` .
|
22
|
+
# In the first form, returns an array of the names of all constants accessible
|
23
|
+
# from the point of call. This list includes the names of all modules and
|
24
|
+
# classes defined in the global scope.
|
25
|
+
#
|
26
|
+
# Module.constants.first(4)
|
27
|
+
# # => [:ARGF, :ARGV, :ArgumentError, :Array]
|
28
|
+
#
|
29
|
+
# Module.constants.include?(:SEEK_SET) # => false
|
30
|
+
#
|
31
|
+
# class IO
|
32
|
+
# Module.constants.include?(:SEEK_SET) # => true
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# The second form calls the instance method `constants`.
|
36
|
+
#
|
40
37
|
def self.constants: () -> ::Array[Integer]
|
41
38
|
|
42
39
|
# Returns the list of `Modules` nested at the point of call.
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# ```
|
40
|
+
#
|
41
|
+
# module M1
|
42
|
+
# module M2
|
43
|
+
# $a = Module.nesting
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
# $a #=> [M1::M2, M1]
|
47
|
+
# $a[0].name #=> "M1::M2"
|
48
|
+
#
|
53
49
|
def self.nesting: () -> ::Array[Module]
|
54
50
|
|
51
|
+
# Returns an array of all modules used in the current scope. The ordering of
|
52
|
+
# modules in the resulting array is not defined.
|
53
|
+
#
|
54
|
+
# module A
|
55
|
+
# refine Object do
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# module B
|
60
|
+
# refine Object do
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# using A
|
65
|
+
# using B
|
66
|
+
# p Module.used_modules
|
67
|
+
#
|
68
|
+
# *produces:*
|
69
|
+
#
|
70
|
+
# [B, A]
|
71
|
+
#
|
55
72
|
def self.used_modules: () -> ::Array[Module]
|
56
73
|
|
74
|
+
# Returns true if *mod* is a subclass of *other*. Returns `nil` if there's no
|
75
|
+
# relationship between the two. (Think of the relationship in terms of the class
|
76
|
+
# definition: "class A < B" implies "A < B".)
|
77
|
+
#
|
57
78
|
def <: (Module other) -> bool?
|
58
79
|
|
80
|
+
# Returns true if *mod* is a subclass of *other* or is the same as *other*.
|
81
|
+
# Returns `nil` if there's no relationship between the two. (Think of the
|
82
|
+
# relationship in terms of the class definition: "class A < B" implies "A < B".)
|
83
|
+
#
|
59
84
|
def <=: (Module other) -> bool?
|
60
85
|
|
86
|
+
# Comparison---Returns -1, 0, +1 or nil depending on whether `module` includes
|
87
|
+
# `other_module`, they are the same, or if `module` is included by
|
88
|
+
# `other_module`.
|
89
|
+
#
|
90
|
+
# Returns `nil` if `module` has no relationship with `other_module`, if
|
91
|
+
# `other_module` is not a module, or if the two values are incomparable.
|
92
|
+
#
|
61
93
|
def <=>: (Module other) -> Integer?
|
62
94
|
|
95
|
+
# Equality --- At the Object level, #== returns `true` only if `obj` and `other`
|
96
|
+
# are the same object. Typically, this method is overridden in descendant
|
97
|
+
# classes to provide class-specific meaning.
|
98
|
+
#
|
99
|
+
# Unlike #==, the #equal? method should never be overridden by subclasses as it
|
100
|
+
# is used to determine object identity (that is, `a.equal?(b)` if and only if
|
101
|
+
# `a` is the same object as `b`):
|
102
|
+
#
|
103
|
+
# obj = "a"
|
104
|
+
# other = obj.dup
|
105
|
+
#
|
106
|
+
# obj == other #=> true
|
107
|
+
# obj.equal? other #=> false
|
108
|
+
# obj.equal? obj #=> true
|
109
|
+
#
|
110
|
+
# The #eql? method returns `true` if `obj` and `other` refer to the same hash
|
111
|
+
# key. This is used by Hash to test members for equality. For any pair of
|
112
|
+
# objects where #eql? returns `true`, the #hash value of both objects must be
|
113
|
+
# equal. So any subclass that overrides #eql? should also override #hash
|
114
|
+
# appropriately.
|
115
|
+
#
|
116
|
+
# For objects of class Object, #eql? is synonymous with #==. Subclasses
|
117
|
+
# normally continue this tradition by aliasing #eql? to their overridden #==
|
118
|
+
# method, but there are exceptions. Numeric types, for example, perform type
|
119
|
+
# conversion across #==, but not across #eql?, so:
|
120
|
+
#
|
121
|
+
# 1 == 1.0 #=> true
|
122
|
+
# 1.eql? 1.0 #=> false
|
123
|
+
#
|
63
124
|
def ==: (untyped other) -> bool
|
64
125
|
|
126
|
+
# Case Equality---Returns `true` if *obj* is an instance of *mod* or an instance
|
127
|
+
# of one of *mod*'s descendants. Of limited use for modules, but can be used in
|
128
|
+
# `case` statements to classify objects by class.
|
129
|
+
#
|
65
130
|
def ===: (untyped other) -> bool
|
66
131
|
|
132
|
+
# Returns true if *mod* is an ancestor of *other*. Returns `nil` if there's no
|
133
|
+
# relationship between the two. (Think of the relationship in terms of the class
|
134
|
+
# definition: "class A < B" implies "B > A".)
|
135
|
+
#
|
67
136
|
def >: (Module other) -> bool?
|
68
137
|
|
138
|
+
# Returns true if *mod* is an ancestor of *other*, or the two modules are the
|
139
|
+
# same. Returns `nil` if there's no relationship between the two. (Think of the
|
140
|
+
# relationship in terms of the class definition: "class A < B" implies "B > A".)
|
141
|
+
#
|
69
142
|
def >=: (Module other) -> bool?
|
70
143
|
|
144
|
+
# Makes *new_name* a new copy of the method *old_name*. This can be used to
|
145
|
+
# retain access to methods that are overridden.
|
146
|
+
#
|
147
|
+
# module Mod
|
148
|
+
# alias_method :orig_exit, :exit
|
149
|
+
# def exit(code=0)
|
150
|
+
# puts "Exiting with code #{code}"
|
151
|
+
# orig_exit(code)
|
152
|
+
# end
|
153
|
+
# end
|
154
|
+
# include Mod
|
155
|
+
# exit(99)
|
156
|
+
#
|
157
|
+
# *produces:*
|
158
|
+
#
|
159
|
+
# Exiting with code 99
|
160
|
+
#
|
71
161
|
def alias_method: (Symbol new_name, Symbol old_name) -> self
|
72
162
|
|
73
163
|
# Returns a list of modules included/prepended in *mod* (including *mod*
|
74
164
|
# itself).
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
# ```
|
165
|
+
#
|
166
|
+
# module Mod
|
167
|
+
# include Math
|
168
|
+
# include Comparable
|
169
|
+
# prepend Enumerable
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# Mod.ancestors #=> [Enumerable, Mod, Comparable, Math]
|
173
|
+
# Math.ancestors #=> [Math]
|
174
|
+
# Enumerable.ancestors #=> [Enumerable]
|
175
|
+
#
|
87
176
|
def ancestors: () -> ::Array[Module]
|
88
177
|
|
178
|
+
# When this module is included in another, Ruby calls #append_features in this
|
179
|
+
# module, passing it the receiving module in *mod*. Ruby's default
|
180
|
+
# implementation is to add the constants, methods, and module variables of this
|
181
|
+
# module to *mod* if this module has not already been added to *mod* or one of
|
182
|
+
# its ancestors. See also Module#include.
|
183
|
+
#
|
89
184
|
def append_features: (Module arg0) -> self
|
90
185
|
|
186
|
+
# Defines a named attribute for this module, where the name is
|
187
|
+
# *symbol.*`id2name`, creating an instance variable (`@name`) and a
|
188
|
+
# corresponding access method to read it. Also creates a method called `name=`
|
189
|
+
# to set the attribute. String arguments are converted to symbols.
|
190
|
+
#
|
191
|
+
# module Mod
|
192
|
+
# attr_accessor(:one, :two)
|
193
|
+
# end
|
194
|
+
# Mod.instance_methods.sort #=> [:one, :one=, :two, :two=]
|
195
|
+
#
|
91
196
|
def `attr_accessor`: (*Symbol | String arg0) -> NilClass
|
92
197
|
|
198
|
+
# Creates instance variables and corresponding methods that return the value of
|
199
|
+
# each instance variable. Equivalent to calling ```attr`*:name*'' on each name
|
200
|
+
# in turn. String arguments are converted to symbols.
|
201
|
+
#
|
93
202
|
def `attr_reader`: (*Symbol | String arg0) -> NilClass
|
94
203
|
|
204
|
+
# Creates an accessor method to allow assignment to the attribute
|
205
|
+
# *symbol*`.id2name`. String arguments are converted to symbols.
|
206
|
+
#
|
95
207
|
def `attr_writer`: (*Symbol | String arg0) -> NilClass
|
96
208
|
|
209
|
+
# Registers *filename* to be loaded (using Kernel::require) the first time that
|
210
|
+
# *module* (which may be a String or a symbol) is accessed in the namespace of
|
211
|
+
# *mod*.
|
212
|
+
#
|
213
|
+
# module A
|
214
|
+
# end
|
215
|
+
# A.autoload(:B, "b")
|
216
|
+
# A::B.doit # autoloads "b"
|
217
|
+
#
|
97
218
|
def autoload: (Symbol _module, String filename) -> NilClass
|
98
219
|
|
99
|
-
|
100
|
-
|
220
|
+
# Returns *filename* to be loaded if *name* is registered as `autoload` in the
|
221
|
+
# namespace of *mod* or one of its ancestors.
|
222
|
+
#
|
223
|
+
# module A
|
224
|
+
# end
|
225
|
+
# A.autoload(:B, "b")
|
226
|
+
# A.autoload?(:B) #=> "b"
|
227
|
+
#
|
228
|
+
# If `inherit` is false, the lookup only checks the autoloads in the receiver:
|
229
|
+
#
|
230
|
+
# class A
|
231
|
+
# autoload :CONST, "const.rb"
|
232
|
+
# end
|
233
|
+
#
|
234
|
+
# class B < A
|
235
|
+
# end
|
236
|
+
#
|
237
|
+
# B.autoload?(:CONST) #=> "const.rb", found in A (ancestor)
|
238
|
+
# B.autoload?(:CONST, false) #=> nil, not found in B itself
|
239
|
+
#
|
240
|
+
def autoload?: (Symbol name, ?bool inherit) -> String?
|
241
|
+
|
242
|
+
# Evaluates the string or block in the context of *mod*, except that when a
|
243
|
+
# block is given, constant/class variable lookup is not affected. This can be
|
244
|
+
# used to add methods to a class. `module_eval` returns the result of evaluating
|
245
|
+
# its argument. The optional *filename* and *lineno* parameters set the text for
|
246
|
+
# error messages.
|
247
|
+
#
|
248
|
+
# class Thing
|
249
|
+
# end
|
250
|
+
# a = %q{def hello() "Hello there!" end}
|
251
|
+
# Thing.module_eval(a)
|
252
|
+
# puts Thing.new.hello()
|
253
|
+
# Thing.module_eval("invalid code", "dummy", 123)
|
254
|
+
#
|
255
|
+
# *produces:*
|
256
|
+
#
|
257
|
+
# Hello there!
|
258
|
+
# dummy:123:in `module_eval': undefined local variable
|
259
|
+
# or method `code' for Thing:Class
|
260
|
+
#
|
101
261
|
def class_eval: (String arg0, ?String filename, ?Integer lineno) -> untyped
|
102
262
|
| [U] (untyped arg0) { (untyped m) -> U } -> U
|
103
263
|
|
264
|
+
# Evaluates the given block in the context of the class/module. The method
|
265
|
+
# defined in the block will belong to the receiver. Any arguments passed to the
|
266
|
+
# method will be passed to the block. This can be used if the block needs to
|
267
|
+
# access instance variables.
|
268
|
+
#
|
269
|
+
# class Thing
|
270
|
+
# end
|
271
|
+
# Thing.class_exec{
|
272
|
+
# def hello() "Hello there!" end
|
273
|
+
# }
|
274
|
+
# puts Thing.new.hello()
|
275
|
+
#
|
276
|
+
# *produces:*
|
277
|
+
#
|
278
|
+
# Hello there!
|
279
|
+
#
|
104
280
|
def class_exec: (*untyped args) { () -> untyped } -> untyped
|
105
281
|
|
282
|
+
# Returns `true` if the given class variable is defined in *obj*. String
|
283
|
+
# arguments are converted to symbols.
|
284
|
+
#
|
285
|
+
# class Fred
|
286
|
+
# @@foo = 99
|
287
|
+
# end
|
288
|
+
# Fred.class_variable_defined?(:@@foo) #=> true
|
289
|
+
# Fred.class_variable_defined?(:@@bar) #=> false
|
290
|
+
#
|
106
291
|
def class_variable_defined?: (Symbol | String arg0) -> bool
|
107
292
|
|
293
|
+
# Returns the value of the given class variable (or throws a NameError
|
294
|
+
# exception). The `@@` part of the variable name should be included for regular
|
295
|
+
# class variables. String arguments are converted to symbols.
|
296
|
+
#
|
297
|
+
# class Fred
|
298
|
+
# @@foo = 99
|
299
|
+
# end
|
300
|
+
# Fred.class_variable_get(:@@foo) #=> 99
|
301
|
+
#
|
108
302
|
def class_variable_get: (Symbol | String arg0) -> untyped
|
109
303
|
|
304
|
+
# Sets the class variable named by *symbol* to the given object. If the class
|
305
|
+
# variable name is passed as a string, that string is converted to a symbol.
|
306
|
+
#
|
307
|
+
# class Fred
|
308
|
+
# @@foo = 99
|
309
|
+
# def foo
|
310
|
+
# @@foo
|
311
|
+
# end
|
312
|
+
# end
|
313
|
+
# Fred.class_variable_set(:@@foo, 101) #=> 101
|
314
|
+
# Fred.new.foo #=> 101
|
315
|
+
#
|
110
316
|
def class_variable_set: (Symbol | String arg0, untyped arg1) -> untyped
|
111
317
|
|
318
|
+
# Returns an array of the names of class variables in *mod*. This includes the
|
319
|
+
# names of class variables in any included modules, unless the *inherit*
|
320
|
+
# parameter is set to `false`.
|
321
|
+
#
|
322
|
+
# class One
|
323
|
+
# @@var1 = 1
|
324
|
+
# end
|
325
|
+
# class Two < One
|
326
|
+
# @@var2 = 2
|
327
|
+
# end
|
328
|
+
# One.class_variables #=> [:@@var1]
|
329
|
+
# Two.class_variables #=> [:@@var2, :@@var1]
|
330
|
+
# Two.class_variables(false) #=> [:@@var2]
|
331
|
+
#
|
112
332
|
def class_variables: (?bool inherit) -> ::Array[Symbol]
|
113
333
|
|
334
|
+
# Says whether *mod* or its ancestors have a constant with the given name:
|
335
|
+
#
|
336
|
+
# Float.const_defined?(:EPSILON) #=> true, found in Float itself
|
337
|
+
# Float.const_defined?("String") #=> true, found in Object (ancestor)
|
338
|
+
# BasicObject.const_defined?(:Hash) #=> false
|
339
|
+
#
|
340
|
+
# If *mod* is a `Module`, additionally `Object` and its ancestors are checked:
|
341
|
+
#
|
342
|
+
# Math.const_defined?(:String) #=> true, found in Object
|
343
|
+
#
|
344
|
+
# In each of the checked classes or modules, if the constant is not present but
|
345
|
+
# there is an autoload for it, `true` is returned directly without autoloading:
|
346
|
+
#
|
347
|
+
# module Admin
|
348
|
+
# autoload :User, 'admin/user'
|
349
|
+
# end
|
350
|
+
# Admin.const_defined?(:User) #=> true
|
351
|
+
#
|
352
|
+
# If the constant is not found the callback `const_missing` is **not** called
|
353
|
+
# and the method returns `false`.
|
354
|
+
#
|
355
|
+
# If `inherit` is false, the lookup only checks the constants in the receiver:
|
356
|
+
#
|
357
|
+
# IO.const_defined?(:SYNC) #=> true, found in File::Constants (ancestor)
|
358
|
+
# IO.const_defined?(:SYNC, false) #=> false, not found in IO itself
|
359
|
+
#
|
360
|
+
# In this case, the same logic for autoloading applies.
|
361
|
+
#
|
362
|
+
# If the argument is not a valid constant name a `NameError` is raised with the
|
363
|
+
# message "wrong constant name *name*":
|
364
|
+
#
|
365
|
+
# Hash.const_defined? 'foobar' #=> NameError: wrong constant name foobar
|
366
|
+
#
|
114
367
|
def const_defined?: (Symbol | String arg0, ?bool inherit) -> bool
|
115
368
|
|
369
|
+
# Checks for a constant with the given name in *mod*. If `inherit` is set, the
|
370
|
+
# lookup will also search the ancestors (and `Object` if *mod* is a `Module`).
|
371
|
+
#
|
372
|
+
# The value of the constant is returned if a definition is found, otherwise a
|
373
|
+
# `NameError` is raised.
|
374
|
+
#
|
375
|
+
# Math.const_get(:PI) #=> 3.14159265358979
|
376
|
+
#
|
377
|
+
# This method will recursively look up constant names if a namespaced class name
|
378
|
+
# is provided. For example:
|
379
|
+
#
|
380
|
+
# module Foo; class Bar; end end
|
381
|
+
# Object.const_get 'Foo::Bar'
|
382
|
+
#
|
383
|
+
# The `inherit` flag is respected on each lookup. For example:
|
384
|
+
#
|
385
|
+
# module Foo
|
386
|
+
# class Bar
|
387
|
+
# VAL = 10
|
388
|
+
# end
|
389
|
+
#
|
390
|
+
# class Baz < Bar; end
|
391
|
+
# end
|
392
|
+
#
|
393
|
+
# Object.const_get 'Foo::Baz::VAL' # => 10
|
394
|
+
# Object.const_get 'Foo::Baz::VAL', false # => NameError
|
395
|
+
#
|
396
|
+
# If the argument is not a valid constant name a `NameError` will be raised with
|
397
|
+
# a warning "wrong constant name".
|
398
|
+
#
|
399
|
+
# Object.const_get 'foobar' #=> NameError: wrong constant name foobar
|
400
|
+
#
|
116
401
|
def const_get: (Symbol | String arg0, ?bool inherit) -> untyped
|
117
402
|
|
403
|
+
# Invoked when a reference is made to an undefined constant in *mod*. It is
|
404
|
+
# passed a symbol for the undefined constant, and returns a value to be used for
|
405
|
+
# that constant. The following code is an example of the same:
|
406
|
+
#
|
407
|
+
# def Foo.const_missing(name)
|
408
|
+
# name # return the constant name as Symbol
|
409
|
+
# end
|
410
|
+
#
|
411
|
+
# Foo::UNDEFINED_CONST #=> :UNDEFINED_CONST: symbol returned
|
412
|
+
#
|
413
|
+
# In the next example when a reference is made to an undefined constant, it
|
414
|
+
# attempts to load a file whose name is the lowercase version of the constant
|
415
|
+
# (thus class `Fred` is assumed to be in file `fred.rb`). If found, it returns
|
416
|
+
# the loaded class. It therefore implements an autoload feature similar to
|
417
|
+
# Kernel#autoload and Module#autoload.
|
418
|
+
#
|
419
|
+
# def Object.const_missing(name)
|
420
|
+
# @looked_for ||= {}
|
421
|
+
# str_name = name.to_s
|
422
|
+
# raise "Class not found: #{name}" if @looked_for[str_name]
|
423
|
+
# @looked_for[str_name] = 1
|
424
|
+
# file = str_name.downcase
|
425
|
+
# require file
|
426
|
+
# klass = const_get(name)
|
427
|
+
# return klass if klass
|
428
|
+
# raise "Class not found: #{name}"
|
429
|
+
# end
|
430
|
+
#
|
118
431
|
def const_missing: (Symbol arg0) -> untyped
|
119
432
|
|
433
|
+
# Sets the named constant to the given object, returning that object. Creates a
|
434
|
+
# new constant if no constant with the given name previously existed.
|
435
|
+
#
|
436
|
+
# Math.const_set("HIGH_SCHOOL_PI", 22.0/7.0) #=> 3.14285714285714
|
437
|
+
# Math::HIGH_SCHOOL_PI - Math::PI #=> 0.00126448926734968
|
438
|
+
#
|
439
|
+
# If `sym` or `str` is not a valid constant name a `NameError` will be raised
|
440
|
+
# with a warning "wrong constant name".
|
441
|
+
#
|
442
|
+
# Object.const_set('foobar', 42) #=> NameError: wrong constant name foobar
|
443
|
+
#
|
120
444
|
def const_set: (Symbol | String arg0, untyped arg1) -> untyped
|
121
445
|
|
446
|
+
# Returns an array of the names of the constants accessible in *mod*. This
|
447
|
+
# includes the names of constants in any included modules (example at start of
|
448
|
+
# section), unless the *inherit* parameter is set to `false`.
|
449
|
+
#
|
450
|
+
# The implementation makes no guarantees about the order in which the constants
|
451
|
+
# are yielded.
|
452
|
+
#
|
453
|
+
# IO.constants.include?(:SYNC) #=> true
|
454
|
+
# IO.constants(false).include?(:SYNC) #=> false
|
455
|
+
#
|
456
|
+
# Also see Module#const_defined?.
|
457
|
+
#
|
122
458
|
def constants: (?bool inherit) -> ::Array[Symbol]
|
123
459
|
|
460
|
+
# Defines an instance method in the receiver. The *method* parameter can be a
|
461
|
+
# `Proc`, a `Method` or an `UnboundMethod` object. If a block is specified, it
|
462
|
+
# is used as the method body. If a block or the *method* parameter has
|
463
|
+
# parameters, they're used as method parameters. This block is evaluated using
|
464
|
+
# #instance_eval.
|
465
|
+
#
|
466
|
+
# class A
|
467
|
+
# def fred
|
468
|
+
# puts "In Fred"
|
469
|
+
# end
|
470
|
+
# def create_method(name, &block)
|
471
|
+
# self.class.define_method(name, &block)
|
472
|
+
# end
|
473
|
+
# define_method(:wilma) { puts "Charge it!" }
|
474
|
+
# define_method(:flint) {|name| puts "I'm #{name}!"}
|
475
|
+
# end
|
476
|
+
# class B < A
|
477
|
+
# define_method(:barney, instance_method(:fred))
|
478
|
+
# end
|
479
|
+
# a = B.new
|
480
|
+
# a.barney
|
481
|
+
# a.wilma
|
482
|
+
# a.flint('Dino')
|
483
|
+
# a.create_method(:betty) { p self }
|
484
|
+
# a.betty
|
485
|
+
#
|
486
|
+
# *produces:*
|
487
|
+
#
|
488
|
+
# In Fred
|
489
|
+
# Charge it!
|
490
|
+
# I'm Dino!
|
491
|
+
# #<B:0x401b39e8>
|
492
|
+
#
|
124
493
|
def define_method: (Symbol | String arg0, ?Proc | Method | UnboundMethod arg1) -> Symbol
|
125
494
|
| (Symbol | String arg0) { () -> untyped } -> Symbol
|
126
495
|
|
@@ -128,121 +497,608 @@ class Module < Object
|
|
128
497
|
|
129
498
|
def equal?: (untyped other) -> bool
|
130
499
|
|
500
|
+
# Extends the specified object by adding this module's constants and methods
|
501
|
+
# (which are added as singleton methods). This is the callback method used by
|
502
|
+
# Object#extend.
|
503
|
+
#
|
504
|
+
# module Picky
|
505
|
+
# def Picky.extend_object(o)
|
506
|
+
# if String === o
|
507
|
+
# puts "Can't add Picky to a String"
|
508
|
+
# else
|
509
|
+
# puts "Picky added to #{o.class}"
|
510
|
+
# super
|
511
|
+
# end
|
512
|
+
# end
|
513
|
+
# end
|
514
|
+
# (s = Array.new).extend Picky # Call Object.extend
|
515
|
+
# (s = "quick brown fox").extend Picky
|
516
|
+
#
|
517
|
+
# *produces:*
|
518
|
+
#
|
519
|
+
# Picky added to Array
|
520
|
+
# Can't add Picky to a String
|
521
|
+
#
|
131
522
|
def extend_object: (untyped arg0) -> untyped
|
132
523
|
|
524
|
+
# The equivalent of `included`, but for extended modules.
|
525
|
+
#
|
526
|
+
# module A
|
527
|
+
# def self.extended(mod)
|
528
|
+
# puts "#{self} extended in #{mod}"
|
529
|
+
# end
|
530
|
+
# end
|
531
|
+
# module Enumerable
|
532
|
+
# extend A
|
533
|
+
# end
|
534
|
+
# # => prints "A extended in Enumerable"
|
535
|
+
#
|
133
536
|
def extended: (Module othermod) -> untyped
|
134
537
|
|
135
|
-
# Prevents further modifications to *mod
|
136
|
-
#
|
538
|
+
# Prevents further modifications to *mod*.
|
539
|
+
#
|
137
540
|
# This method returns self.
|
541
|
+
#
|
138
542
|
def freeze: () -> self
|
139
543
|
|
544
|
+
# Invokes Module.append_features on each parameter in reverse order.
|
545
|
+
#
|
140
546
|
def `include`: (*Module arg0) -> self
|
141
547
|
|
142
|
-
|
143
|
-
|
548
|
+
# Returns `true` if *module* is included in *mod* or one of *mod*'s ancestors.
|
549
|
+
#
|
550
|
+
# module A
|
551
|
+
# end
|
552
|
+
# class B
|
553
|
+
# include A
|
554
|
+
# end
|
555
|
+
# class C < B
|
556
|
+
# end
|
557
|
+
# B.include?(A) #=> true
|
558
|
+
# C.include?(A) #=> true
|
559
|
+
# A.include?(A) #=> false
|
560
|
+
#
|
561
|
+
def include?: (Module arg0) -> bool
|
562
|
+
|
563
|
+
# Callback invoked whenever the receiver is included in another module or class.
|
564
|
+
# This should be used in preference to `Module.append_features` if your code
|
565
|
+
# wants to perform some action when a module is included in another.
|
566
|
+
#
|
567
|
+
# module A
|
568
|
+
# def A.included(mod)
|
569
|
+
# puts "#{self} included in #{mod}"
|
570
|
+
# end
|
571
|
+
# end
|
572
|
+
# module Enumerable
|
573
|
+
# include A
|
574
|
+
# end
|
575
|
+
# # => prints "A included in Enumerable"
|
576
|
+
#
|
144
577
|
def included: (Module othermod) -> untyped
|
145
578
|
|
146
|
-
# Returns the list of modules included in *mod
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
#
|
158
|
-
# ```
|
579
|
+
# Returns the list of modules included in *mod*.
|
580
|
+
#
|
581
|
+
# module Mixin
|
582
|
+
# end
|
583
|
+
#
|
584
|
+
# module Outer
|
585
|
+
# include Mixin
|
586
|
+
# end
|
587
|
+
#
|
588
|
+
# Mixin.included_modules #=> []
|
589
|
+
# Outer.included_modules #=> [Mixin]
|
590
|
+
#
|
159
591
|
def included_modules: () -> ::Array[Module]
|
160
592
|
|
593
|
+
# Creates a new anonymous module. If a block is given, it is passed the module
|
594
|
+
# object, and the block is evaluated in the context of this module like
|
595
|
+
# #module_eval.
|
596
|
+
#
|
597
|
+
# fred = Module.new do
|
598
|
+
# def meth1
|
599
|
+
# "hello"
|
600
|
+
# end
|
601
|
+
# def meth2
|
602
|
+
# "bye"
|
603
|
+
# end
|
604
|
+
# end
|
605
|
+
# a = "my string"
|
606
|
+
# a.extend(fred) #=> "my string"
|
607
|
+
# a.meth1 #=> "hello"
|
608
|
+
# a.meth2 #=> "bye"
|
609
|
+
#
|
610
|
+
# Assign the module to a constant (name starting uppercase) if you want to treat
|
611
|
+
# it like a regular module.
|
612
|
+
#
|
161
613
|
def initialize: () -> Object
|
162
614
|
| () { (Module arg0) -> untyped } -> void
|
163
615
|
|
616
|
+
# Returns an `UnboundMethod` representing the given instance method in *mod*.
|
617
|
+
#
|
618
|
+
# class Interpreter
|
619
|
+
# def do_a() print "there, "; end
|
620
|
+
# def do_d() print "Hello "; end
|
621
|
+
# def do_e() print "!\n"; end
|
622
|
+
# def do_v() print "Dave"; end
|
623
|
+
# Dispatcher = {
|
624
|
+
# "a" => instance_method(:do_a),
|
625
|
+
# "d" => instance_method(:do_d),
|
626
|
+
# "e" => instance_method(:do_e),
|
627
|
+
# "v" => instance_method(:do_v)
|
628
|
+
# }
|
629
|
+
# def interpret(string)
|
630
|
+
# string.each_char {|b| Dispatcher[b].bind(self).call }
|
631
|
+
# end
|
632
|
+
# end
|
633
|
+
#
|
634
|
+
# interpreter = Interpreter.new
|
635
|
+
# interpreter.interpret('dave')
|
636
|
+
#
|
637
|
+
# *produces:*
|
638
|
+
#
|
639
|
+
# Hello there, Dave!
|
640
|
+
#
|
164
641
|
def instance_method: (Symbol arg0) -> UnboundMethod
|
165
642
|
|
643
|
+
# Returns an array containing the names of the public and protected instance
|
644
|
+
# methods in the receiver. For a module, these are the public and protected
|
645
|
+
# methods; for a class, they are the instance (not singleton) methods. If the
|
646
|
+
# optional parameter is `false`, the methods of any ancestors are not included.
|
647
|
+
#
|
648
|
+
# module A
|
649
|
+
# def method1() end
|
650
|
+
# end
|
651
|
+
# class B
|
652
|
+
# include A
|
653
|
+
# def method2() end
|
654
|
+
# end
|
655
|
+
# class C < B
|
656
|
+
# def method3() end
|
657
|
+
# end
|
658
|
+
#
|
659
|
+
# A.instance_methods(false) #=> [:method1]
|
660
|
+
# B.instance_methods(false) #=> [:method2]
|
661
|
+
# B.instance_methods(true).include?(:method1) #=> true
|
662
|
+
# C.instance_methods(false) #=> [:method3]
|
663
|
+
# C.instance_methods.include?(:method2) #=> true
|
664
|
+
#
|
166
665
|
def instance_methods: (?bool include_super) -> ::Array[Symbol]
|
167
666
|
|
667
|
+
# Invoked as a callback whenever an instance method is added to the receiver.
|
668
|
+
#
|
669
|
+
# module Chatty
|
670
|
+
# def self.method_added(method_name)
|
671
|
+
# puts "Adding #{method_name.inspect}"
|
672
|
+
# end
|
673
|
+
# def self.some_class_method() end
|
674
|
+
# def some_instance_method() end
|
675
|
+
# end
|
676
|
+
#
|
677
|
+
# *produces:*
|
678
|
+
#
|
679
|
+
# Adding :some_instance_method
|
680
|
+
#
|
168
681
|
def method_added: (Symbol meth) -> untyped
|
169
682
|
|
170
|
-
|
171
|
-
|
683
|
+
# Returns `true` if the named method is defined by *mod*. If *inherit* is set,
|
684
|
+
# the lookup will also search *mod*'s ancestors. Public and protected methods
|
685
|
+
# are matched. String arguments are converted to symbols.
|
686
|
+
#
|
687
|
+
# module A
|
688
|
+
# def method1() end
|
689
|
+
# def protected_method1() end
|
690
|
+
# protected :protected_method1
|
691
|
+
# end
|
692
|
+
# class B
|
693
|
+
# def method2() end
|
694
|
+
# def private_method2() end
|
695
|
+
# private :private_method2
|
696
|
+
# end
|
697
|
+
# class C < B
|
698
|
+
# include A
|
699
|
+
# def method3() end
|
700
|
+
# end
|
701
|
+
#
|
702
|
+
# A.method_defined? :method1 #=> true
|
703
|
+
# C.method_defined? "method1" #=> true
|
704
|
+
# C.method_defined? "method2" #=> true
|
705
|
+
# C.method_defined? "method2", true #=> true
|
706
|
+
# C.method_defined? "method2", false #=> false
|
707
|
+
# C.method_defined? "method3" #=> true
|
708
|
+
# C.method_defined? "protected_method1" #=> true
|
709
|
+
# C.method_defined? "method4" #=> false
|
710
|
+
# C.method_defined? "private_method2" #=> false
|
711
|
+
#
|
712
|
+
def method_defined?: (Symbol | String arg0, ?bool inherit) -> bool
|
713
|
+
|
714
|
+
# Invoked as a callback whenever an instance method is removed from the
|
715
|
+
# receiver.
|
716
|
+
#
|
717
|
+
# module Chatty
|
718
|
+
# def self.method_removed(method_name)
|
719
|
+
# puts "Removing #{method_name.inspect}"
|
720
|
+
# end
|
721
|
+
# def self.some_class_method() end
|
722
|
+
# def some_instance_method() end
|
723
|
+
# class << self
|
724
|
+
# remove_method :some_class_method
|
725
|
+
# end
|
726
|
+
# remove_method :some_instance_method
|
727
|
+
# end
|
728
|
+
#
|
729
|
+
# *produces:*
|
730
|
+
#
|
731
|
+
# Removing :some_instance_method
|
732
|
+
#
|
172
733
|
def method_removed: (Symbol method_name) -> untyped
|
173
734
|
|
735
|
+
# Evaluates the string or block in the context of *mod*, except that when a
|
736
|
+
# block is given, constant/class variable lookup is not affected. This can be
|
737
|
+
# used to add methods to a class. `module_eval` returns the result of evaluating
|
738
|
+
# its argument. The optional *filename* and *lineno* parameters set the text for
|
739
|
+
# error messages.
|
740
|
+
#
|
741
|
+
# class Thing
|
742
|
+
# end
|
743
|
+
# a = %q{def hello() "Hello there!" end}
|
744
|
+
# Thing.module_eval(a)
|
745
|
+
# puts Thing.new.hello()
|
746
|
+
# Thing.module_eval("invalid code", "dummy", 123)
|
747
|
+
#
|
748
|
+
# *produces:*
|
749
|
+
#
|
750
|
+
# Hello there!
|
751
|
+
# dummy:123:in `module_eval': undefined local variable
|
752
|
+
# or method `code' for Thing:Class
|
753
|
+
#
|
174
754
|
def module_eval: (String arg0, ?String filename, ?Integer lineno) -> untyped
|
175
755
|
| [U] (untyped arg0) { (untyped m) -> U } -> U
|
176
756
|
|
757
|
+
# Evaluates the given block in the context of the class/module. The method
|
758
|
+
# defined in the block will belong to the receiver. Any arguments passed to the
|
759
|
+
# method will be passed to the block. This can be used if the block needs to
|
760
|
+
# access instance variables.
|
761
|
+
#
|
762
|
+
# class Thing
|
763
|
+
# end
|
764
|
+
# Thing.class_exec{
|
765
|
+
# def hello() "Hello there!" end
|
766
|
+
# }
|
767
|
+
# puts Thing.new.hello()
|
768
|
+
#
|
769
|
+
# *produces:*
|
770
|
+
#
|
771
|
+
# Hello there!
|
772
|
+
#
|
177
773
|
def module_exec: (*untyped args) { () -> untyped } -> untyped
|
178
774
|
|
775
|
+
# Creates module functions for the named methods. These functions may be called
|
776
|
+
# with the module as a receiver, and also become available as instance methods
|
777
|
+
# to classes that mix in the module. Module functions are copies of the
|
778
|
+
# original, and so may be changed independently. The instance-method versions
|
779
|
+
# are made private. If used with no arguments, subsequently defined methods
|
780
|
+
# become module functions. String arguments are converted to symbols.
|
781
|
+
#
|
782
|
+
# module Mod
|
783
|
+
# def one
|
784
|
+
# "This is one"
|
785
|
+
# end
|
786
|
+
# module_function :one
|
787
|
+
# end
|
788
|
+
# class Cls
|
789
|
+
# include Mod
|
790
|
+
# def call_one
|
791
|
+
# one
|
792
|
+
# end
|
793
|
+
# end
|
794
|
+
# Mod.one #=> "This is one"
|
795
|
+
# c = Cls.new
|
796
|
+
# c.call_one #=> "This is one"
|
797
|
+
# module Mod
|
798
|
+
# def one
|
799
|
+
# "This is the new one"
|
800
|
+
# end
|
801
|
+
# end
|
802
|
+
# Mod.one #=> "This is one"
|
803
|
+
# c.call_one #=> "This is the new one"
|
804
|
+
#
|
179
805
|
def module_function: (*Symbol | String arg0) -> self
|
180
806
|
|
181
|
-
# Returns the name of the module *mod
|
182
|
-
#
|
807
|
+
# Returns the name of the module *mod*. Returns nil for anonymous modules.
|
808
|
+
#
|
183
809
|
def name: () -> String?
|
184
810
|
|
811
|
+
# Invokes Module.prepend_features on each parameter in reverse order.
|
812
|
+
#
|
185
813
|
def `prepend`: (*Module arg0) -> self
|
186
814
|
|
815
|
+
# When this module is prepended in another, Ruby calls #prepend_features in this
|
816
|
+
# module, passing it the receiving module in *mod*. Ruby's default
|
817
|
+
# implementation is to overlay the constants, methods, and module variables of
|
818
|
+
# this module to *mod* if this module has not already been added to *mod* or one
|
819
|
+
# of its ancestors. See also Module#prepend.
|
820
|
+
#
|
187
821
|
def prepend_features: (Module arg0) -> self
|
188
822
|
|
823
|
+
# The equivalent of `included`, but for prepended modules.
|
824
|
+
#
|
825
|
+
# module A
|
826
|
+
# def self.prepended(mod)
|
827
|
+
# puts "#{self} prepended to #{mod}"
|
828
|
+
# end
|
829
|
+
# end
|
830
|
+
# module Enumerable
|
831
|
+
# prepend A
|
832
|
+
# end
|
833
|
+
# # => prints "A prepended to Enumerable"
|
834
|
+
#
|
189
835
|
def prepended: (Module othermod) -> untyped
|
190
836
|
|
837
|
+
# With no arguments, sets the default visibility for subsequently defined
|
838
|
+
# methods to private. With arguments, sets the named methods to have private
|
839
|
+
# visibility. String arguments are converted to symbols.
|
840
|
+
#
|
841
|
+
# module Mod
|
842
|
+
# def a() end
|
843
|
+
# def b() end
|
844
|
+
# private
|
845
|
+
# def c() end
|
846
|
+
# private :a
|
847
|
+
# end
|
848
|
+
# Mod.private_instance_methods #=> [:a, :c]
|
849
|
+
#
|
850
|
+
# Note that to show a private method on RDoc, use `:doc:`.
|
851
|
+
#
|
191
852
|
def `private`: (*Symbol | String arg0) -> self
|
192
853
|
|
854
|
+
# Makes existing class methods private. Often used to hide the default
|
855
|
+
# constructor `new`.
|
856
|
+
#
|
857
|
+
# String arguments are converted to symbols.
|
858
|
+
#
|
859
|
+
# class SimpleSingleton # Not thread safe
|
860
|
+
# private_class_method :new
|
861
|
+
# def SimpleSingleton.create(*args, &block)
|
862
|
+
# @me = new(*args, &block) if ! @me
|
863
|
+
# @me
|
864
|
+
# end
|
865
|
+
# end
|
866
|
+
#
|
193
867
|
def private_class_method: (*Symbol | String arg0) -> self
|
194
868
|
|
869
|
+
# Makes a list of existing constants private.
|
870
|
+
#
|
195
871
|
def private_constant: (*Symbol arg0) -> self
|
196
872
|
|
873
|
+
# Returns a list of the private instance methods defined in *mod*. If the
|
874
|
+
# optional parameter is `false`, the methods of any ancestors are not included.
|
875
|
+
#
|
876
|
+
# module Mod
|
877
|
+
# def method1() end
|
878
|
+
# private :method1
|
879
|
+
# def method2() end
|
880
|
+
# end
|
881
|
+
# Mod.instance_methods #=> [:method2]
|
882
|
+
# Mod.private_instance_methods #=> [:method1]
|
883
|
+
#
|
197
884
|
def private_instance_methods: (?bool include_super) -> ::Array[Symbol]
|
198
885
|
|
199
|
-
|
200
|
-
|
886
|
+
# Returns `true` if the named private method is defined by *mod*. If *inherit*
|
887
|
+
# is set, the lookup will also search *mod*'s ancestors. String arguments are
|
888
|
+
# converted to symbols.
|
889
|
+
#
|
890
|
+
# module A
|
891
|
+
# def method1() end
|
892
|
+
# end
|
893
|
+
# class B
|
894
|
+
# private
|
895
|
+
# def method2() end
|
896
|
+
# end
|
897
|
+
# class C < B
|
898
|
+
# include A
|
899
|
+
# def method3() end
|
900
|
+
# end
|
901
|
+
#
|
902
|
+
# A.method_defined? :method1 #=> true
|
903
|
+
# C.private_method_defined? "method1" #=> false
|
904
|
+
# C.private_method_defined? "method2" #=> true
|
905
|
+
# C.private_method_defined? "method2", true #=> true
|
906
|
+
# C.private_method_defined? "method2", false #=> false
|
907
|
+
# C.method_defined? "method2" #=> false
|
908
|
+
#
|
909
|
+
def private_method_defined?: (Symbol | String arg0, ?bool inherit) -> bool
|
910
|
+
|
911
|
+
# With no arguments, sets the default visibility for subsequently defined
|
912
|
+
# methods to protected. With arguments, sets the named methods to have protected
|
913
|
+
# visibility. String arguments are converted to symbols.
|
914
|
+
#
|
915
|
+
# If a method has protected visibility, it is callable only where `self` of the
|
916
|
+
# context is the same as the method. (method definition or instance_eval). This
|
917
|
+
# behavior is different from Java's protected method. Usually `private` should
|
918
|
+
# be used.
|
919
|
+
#
|
920
|
+
# Note that a protected method is slow because it can't use inline cache.
|
921
|
+
#
|
922
|
+
# To show a private method on RDoc, use `:doc:` instead of this.
|
923
|
+
#
|
201
924
|
def protected: (*Symbol | String arg0) -> self
|
202
925
|
|
926
|
+
# Returns a list of the protected instance methods defined in *mod*. If the
|
927
|
+
# optional parameter is `false`, the methods of any ancestors are not included.
|
928
|
+
#
|
203
929
|
def protected_instance_methods: (?bool include_super) -> ::Array[Symbol]
|
204
930
|
|
205
|
-
|
206
|
-
|
931
|
+
# Returns `true` if the named protected method is defined *mod*. If *inherit*
|
932
|
+
# is set, the lookup will also search *mod*'s ancestors. String arguments are
|
933
|
+
# converted to symbols.
|
934
|
+
#
|
935
|
+
# module A
|
936
|
+
# def method1() end
|
937
|
+
# end
|
938
|
+
# class B
|
939
|
+
# protected
|
940
|
+
# def method2() end
|
941
|
+
# end
|
942
|
+
# class C < B
|
943
|
+
# include A
|
944
|
+
# def method3() end
|
945
|
+
# end
|
946
|
+
#
|
947
|
+
# A.method_defined? :method1 #=> true
|
948
|
+
# C.protected_method_defined? "method1" #=> false
|
949
|
+
# C.protected_method_defined? "method2" #=> true
|
950
|
+
# C.protected_method_defined? "method2", true #=> true
|
951
|
+
# C.protected_method_defined? "method2", false #=> false
|
952
|
+
# C.method_defined? "method2" #=> true
|
953
|
+
#
|
954
|
+
def protected_method_defined?: (Symbol | String arg0, ?bool inherit) -> bool
|
955
|
+
|
956
|
+
# With no arguments, sets the default visibility for subsequently defined
|
957
|
+
# methods to public. With arguments, sets the named methods to have public
|
958
|
+
# visibility. String arguments are converted to symbols.
|
959
|
+
#
|
207
960
|
def `public`: (*Symbol | String arg0) -> self
|
208
961
|
|
962
|
+
# Makes a list of existing class methods public.
|
963
|
+
#
|
964
|
+
# String arguments are converted to symbols.
|
965
|
+
#
|
209
966
|
def public_class_method: (*Symbol | String arg0) -> self
|
210
967
|
|
968
|
+
# Makes a list of existing constants public.
|
969
|
+
#
|
211
970
|
def public_constant: (*Symbol arg0) -> self
|
212
971
|
|
972
|
+
# Similar to *instance_method*, searches public method only.
|
973
|
+
#
|
213
974
|
def public_instance_method: (Symbol arg0) -> UnboundMethod
|
214
975
|
|
976
|
+
# Returns a list of the public instance methods defined in *mod*. If the
|
977
|
+
# optional parameter is `false`, the methods of any ancestors are not included.
|
978
|
+
#
|
215
979
|
def public_instance_methods: (?bool include_super) -> ::Array[Symbol]
|
216
980
|
|
217
|
-
|
218
|
-
|
981
|
+
# Returns `true` if the named public method is defined by *mod*. If *inherit*
|
982
|
+
# is set, the lookup will also search *mod*'s ancestors. String arguments are
|
983
|
+
# converted to symbols.
|
984
|
+
#
|
985
|
+
# module A
|
986
|
+
# def method1() end
|
987
|
+
# end
|
988
|
+
# class B
|
989
|
+
# protected
|
990
|
+
# def method2() end
|
991
|
+
# end
|
992
|
+
# class C < B
|
993
|
+
# include A
|
994
|
+
# def method3() end
|
995
|
+
# end
|
996
|
+
#
|
997
|
+
# A.method_defined? :method1 #=> true
|
998
|
+
# C.public_method_defined? "method1" #=> true
|
999
|
+
# C.public_method_defined? "method1", true #=> true
|
1000
|
+
# C.public_method_defined? "method1", false #=> true
|
1001
|
+
# C.public_method_defined? "method2" #=> false
|
1002
|
+
# C.method_defined? "method2" #=> true
|
1003
|
+
#
|
1004
|
+
def public_method_defined?: (Symbol | String arg0, ?bool inherit) -> bool
|
1005
|
+
|
1006
|
+
# Refine *mod* in the receiver.
|
1007
|
+
#
|
1008
|
+
# Returns a module, where refined methods are defined.
|
1009
|
+
#
|
219
1010
|
def refine: (Class arg0) { (untyped arg0) -> untyped } -> self
|
220
1011
|
|
1012
|
+
# Removes the definition of the *sym*, returning that constant's value.
|
1013
|
+
#
|
1014
|
+
# class Dummy
|
1015
|
+
# @@var = 99
|
1016
|
+
# puts @@var
|
1017
|
+
# remove_class_variable(:@@var)
|
1018
|
+
# p(defined? @@var)
|
1019
|
+
# end
|
1020
|
+
#
|
1021
|
+
# *produces:*
|
1022
|
+
#
|
1023
|
+
# 99
|
1024
|
+
# nil
|
1025
|
+
#
|
221
1026
|
def remove_class_variable: (Symbol arg0) -> untyped
|
222
1027
|
|
1028
|
+
# Removes the definition of the given constant, returning that constant's
|
1029
|
+
# previous value. If that constant referred to a module, this will not change
|
1030
|
+
# that module's name and can lead to confusion.
|
1031
|
+
#
|
223
1032
|
def remove_const: (Symbol arg0) -> untyped
|
224
1033
|
|
1034
|
+
# Removes the method identified by *symbol* from the current class. For an
|
1035
|
+
# example, see Module#undef_method. String arguments are converted to symbols.
|
1036
|
+
#
|
225
1037
|
def remove_method: (Symbol | String arg0) -> self
|
226
1038
|
|
227
|
-
# Returns `true` if *mod* is a singleton class or `false` if it is an
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
|
236
|
-
|
237
|
-
|
1039
|
+
# Returns `true` if *mod* is a singleton class or `false` if it is an ordinary
|
1040
|
+
# class or module.
|
1041
|
+
#
|
1042
|
+
# class C
|
1043
|
+
# end
|
1044
|
+
# C.singleton_class? #=> false
|
1045
|
+
# C.singleton_class.singleton_class? #=> true
|
1046
|
+
#
|
1047
|
+
def singleton_class?: () -> bool
|
1048
|
+
|
1049
|
+
# Returns a string representing this module or class. For basic classes and
|
1050
|
+
# modules, this is the name. For singletons, we show information on the thing
|
1051
|
+
# we're attached to as well.
|
1052
|
+
#
|
238
1053
|
def to_s: () -> String
|
239
1054
|
|
240
|
-
|
241
|
-
|
1055
|
+
# Prevents the current class from responding to calls to the named method.
|
1056
|
+
# Contrast this with `remove_method`, which deletes the method from the
|
1057
|
+
# particular class; Ruby will still search superclasses and mixed-in modules for
|
1058
|
+
# a possible receiver. String arguments are converted to symbols.
|
1059
|
+
#
|
1060
|
+
# class Parent
|
1061
|
+
# def hello
|
1062
|
+
# puts "In parent"
|
1063
|
+
# end
|
1064
|
+
# end
|
1065
|
+
# class Child < Parent
|
1066
|
+
# def hello
|
1067
|
+
# puts "In child"
|
1068
|
+
# end
|
1069
|
+
# end
|
1070
|
+
#
|
1071
|
+
# c = Child.new
|
1072
|
+
# c.hello
|
1073
|
+
#
|
1074
|
+
# class Child
|
1075
|
+
# remove_method :hello # remove from child, still in parent
|
1076
|
+
# end
|
1077
|
+
# c.hello
|
1078
|
+
#
|
1079
|
+
# class Child
|
1080
|
+
# undef_method :hello # prevent any calls to 'hello'
|
1081
|
+
# end
|
1082
|
+
# c.hello
|
1083
|
+
#
|
1084
|
+
# *produces:*
|
1085
|
+
#
|
1086
|
+
# In child
|
1087
|
+
# In parent
|
1088
|
+
# prog.rb:23: undefined method `hello' for #<Child:0x401b3bb4> (NoMethodError)
|
1089
|
+
#
|
1090
|
+
def undef_method: (Symbol | String arg0) -> self
|
1091
|
+
|
1092
|
+
# Import class refinements from *module* into the current class or module
|
1093
|
+
# definition.
|
1094
|
+
#
|
242
1095
|
def using: (Module arg0) -> self
|
243
1096
|
|
244
|
-
# Alias for: [to\_s](Module.downloaded.ruby_doc#method-i-to_s)
|
245
1097
|
def inspect: () -> String
|
246
1098
|
|
1099
|
+
# The first form is equivalent to #attr_reader. The second form is equivalent to
|
1100
|
+
# `attr_accessor(name)` but deprecated. The last form is equivalent to
|
1101
|
+
# `attr_reader(name)` but deprecated.
|
1102
|
+
#
|
247
1103
|
def attr: (*Symbol | String arg0) -> NilClass
|
248
1104
|
end
|