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,91 +1,290 @@
|
|
1
|
+
# Document-class: TracePoint
|
2
|
+
#
|
3
|
+
# A class that provides the functionality of Kernel#set_trace_func in a nice
|
4
|
+
# Object-Oriented API.
|
5
|
+
#
|
6
|
+
# ## Example
|
7
|
+
#
|
8
|
+
# We can use TracePoint to gather information specifically for exceptions:
|
9
|
+
#
|
10
|
+
# trace = TracePoint.new(:raise) do |tp|
|
11
|
+
# p [tp.lineno, tp.event, tp.raised_exception]
|
12
|
+
# end
|
13
|
+
# #=> #<TracePoint:disabled>
|
14
|
+
#
|
15
|
+
# trace.enable
|
16
|
+
# #=> false
|
17
|
+
#
|
18
|
+
# 0 / 0
|
19
|
+
# #=> [5, :raise, #<ZeroDivisionError: divided by 0>]
|
20
|
+
#
|
21
|
+
# ## Events
|
22
|
+
#
|
23
|
+
# If you don't specify the type of events you want to listen for, TracePoint
|
24
|
+
# will include all available events.
|
25
|
+
#
|
26
|
+
# **Note** do not depend on current event set, as this list is subject to
|
27
|
+
# change. Instead, it is recommended you specify the type of events you want to
|
28
|
+
# use.
|
29
|
+
#
|
30
|
+
# To filter what is traced, you can pass any of the following as `events`:
|
31
|
+
#
|
32
|
+
# `:line`
|
33
|
+
# : execute code on a new line
|
34
|
+
# `:class`
|
35
|
+
# : start a class or module definition
|
36
|
+
# `:end`
|
37
|
+
# : finish a class or module definition
|
38
|
+
# `:call`
|
39
|
+
# : call a Ruby method
|
40
|
+
# `:return`
|
41
|
+
# : return from a Ruby method
|
42
|
+
# `:c_call`
|
43
|
+
# : call a C-language routine
|
44
|
+
# `:c_return`
|
45
|
+
# : return from a C-language routine
|
46
|
+
# `:raise`
|
47
|
+
# : raise an exception
|
48
|
+
# `:b_call`
|
49
|
+
# : event hook at block entry
|
50
|
+
# `:b_return`
|
51
|
+
# : event hook at block ending
|
52
|
+
# `:thread_begin`
|
53
|
+
# : event hook at thread beginning
|
54
|
+
# `:thread_end`
|
55
|
+
# : event hook at thread ending
|
56
|
+
# `:fiber_switch`
|
57
|
+
# : event hook at fiber switch
|
58
|
+
# `:script_compiled`
|
59
|
+
# : new Ruby code compiled (with `eval`, `load` or `require`)
|
60
|
+
#
|
61
|
+
#
|
1
62
|
class TracePoint < Object
|
63
|
+
# Returns a new TracePoint object, not enabled by default.
|
64
|
+
#
|
65
|
+
# Next, in order to activate the trace, you must use TracePoint#enable
|
66
|
+
#
|
67
|
+
# trace = TracePoint.new(:call) do |tp|
|
68
|
+
# p [tp.lineno, tp.defined_class, tp.method_id, tp.event]
|
69
|
+
# end
|
70
|
+
# #=> #<TracePoint:disabled>
|
71
|
+
#
|
72
|
+
# trace.enable
|
73
|
+
# #=> false
|
74
|
+
#
|
75
|
+
# puts "Hello, TracePoint!"
|
76
|
+
# # ...
|
77
|
+
# # [48, IRB::Notifier::AbstractNotifier, :printf, :call]
|
78
|
+
# # ...
|
79
|
+
#
|
80
|
+
# When you want to deactivate the trace, you must use TracePoint#disable
|
81
|
+
#
|
82
|
+
# trace.disable
|
83
|
+
#
|
84
|
+
# See TracePoint@Events for possible events and more information.
|
85
|
+
#
|
86
|
+
# A block must be given, otherwise an ArgumentError is raised.
|
87
|
+
#
|
88
|
+
# If the trace method isn't included in the given events filter, a RuntimeError
|
89
|
+
# is raised.
|
90
|
+
#
|
91
|
+
# TracePoint.trace(:line) do |tp|
|
92
|
+
# p tp.raised_exception
|
93
|
+
# end
|
94
|
+
# #=> RuntimeError: 'raised_exception' not supported by this event
|
95
|
+
#
|
96
|
+
# If the trace method is called outside block, a RuntimeError is raised.
|
97
|
+
#
|
98
|
+
# TracePoint.trace(:line) do |tp|
|
99
|
+
# $tp = tp
|
100
|
+
# end
|
101
|
+
# $tp.lineno #=> access from outside (RuntimeError)
|
102
|
+
#
|
103
|
+
# Access from other threads is also forbidden.
|
104
|
+
#
|
2
105
|
def initialize: (*Symbol events) { (TracePoint tp) -> void } -> void
|
3
106
|
|
4
|
-
# Returns internal information of
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# [TracePoint](TracePoint.downloaded.ruby_doc) itself.
|
107
|
+
# Returns internal information of TracePoint.
|
108
|
+
#
|
109
|
+
# The contents of the returned value are implementation specific. It may be
|
110
|
+
# changed in future.
|
111
|
+
#
|
112
|
+
# This method is only for debugging TracePoint itself.
|
113
|
+
#
|
12
114
|
def self.stat: () -> untyped
|
13
115
|
|
116
|
+
# Document-method: trace
|
117
|
+
#
|
118
|
+
# A convenience method for TracePoint.new, that activates the trace
|
119
|
+
# automatically.
|
120
|
+
#
|
121
|
+
# trace = TracePoint.trace(:call) { |tp| [tp.lineno, tp.event] }
|
122
|
+
# #=> #<TracePoint:enabled>
|
123
|
+
#
|
124
|
+
# trace.enabled? #=> true
|
125
|
+
#
|
14
126
|
def self.trace: (*Symbol events) { (TracePoint tp) -> void } -> TracePoint
|
15
127
|
|
16
128
|
# Return the generated binding object from event
|
129
|
+
#
|
17
130
|
def binding: () -> Binding
|
18
131
|
|
19
132
|
# Return the called name of the method being called
|
133
|
+
#
|
20
134
|
def callee_id: () -> Symbol
|
21
135
|
|
22
|
-
|
136
|
+
# Return class or module of the method being called.
|
137
|
+
#
|
138
|
+
# class C; def foo; end; end
|
139
|
+
# trace = TracePoint.new(:call) do |tp|
|
140
|
+
# p tp.defined_class #=> C
|
141
|
+
# end.enable do
|
142
|
+
# C.new.foo
|
143
|
+
# end
|
144
|
+
#
|
145
|
+
# If method is defined by a module, then that module is returned.
|
146
|
+
#
|
147
|
+
# module M; def foo; end; end
|
148
|
+
# class C; include M; end;
|
149
|
+
# trace = TracePoint.new(:call) do |tp|
|
150
|
+
# p tp.defined_class #=> M
|
151
|
+
# end.enable do
|
152
|
+
# C.new.foo
|
153
|
+
# end
|
154
|
+
#
|
155
|
+
# **Note:** #defined_class returns singleton class.
|
156
|
+
#
|
157
|
+
# 6th block parameter of Kernel#set_trace_func passes original class of attached
|
158
|
+
# by singleton class.
|
159
|
+
#
|
160
|
+
# **This is a difference between Kernel#set_trace_func and TracePoint.**
|
161
|
+
#
|
162
|
+
# class C; def self.foo; end; end
|
163
|
+
# trace = TracePoint.new(:call) do |tp|
|
164
|
+
# p tp.defined_class #=> #<Class:C>
|
165
|
+
# end.enable do
|
166
|
+
# C.foo
|
167
|
+
# end
|
168
|
+
#
|
169
|
+
def defined_class: () -> Module
|
23
170
|
|
24
171
|
# Deactivates the trace
|
25
|
-
#
|
172
|
+
#
|
26
173
|
# Return true if trace was enabled. Return false if trace was disabled.
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# the block.
|
37
|
-
#
|
38
|
-
# ```ruby
|
39
|
-
# trace.enabled?
|
40
|
-
# #=> true
|
41
|
-
#
|
42
|
-
# trace.disable do
|
174
|
+
#
|
175
|
+
# trace.enabled? #=> true
|
176
|
+
# trace.disable #=> true (previous status)
|
177
|
+
# trace.enabled? #=> false
|
178
|
+
# trace.disable #=> false
|
179
|
+
#
|
180
|
+
# If a block is given, the trace will only be disable within the scope of the
|
181
|
+
# block.
|
182
|
+
#
|
43
183
|
# trace.enabled?
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
184
|
+
# #=> true
|
185
|
+
#
|
186
|
+
# trace.disable do
|
187
|
+
# trace.enabled?
|
188
|
+
# # only disabled for this block
|
189
|
+
# end
|
190
|
+
#
|
191
|
+
# trace.enabled?
|
192
|
+
# #=> true
|
193
|
+
#
|
51
194
|
# Note: You cannot access event hooks within the block.
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# ```
|
195
|
+
#
|
196
|
+
# trace.disable { p tp.lineno }
|
197
|
+
# #=> RuntimeError: access from outside
|
198
|
+
#
|
57
199
|
def disable: () -> bool
|
58
200
|
| () { () -> void } -> void
|
59
201
|
|
202
|
+
# Activates the trace.
|
203
|
+
#
|
204
|
+
# Returns `true` if trace was enabled. Returns `false` if trace was disabled.
|
205
|
+
#
|
206
|
+
# trace.enabled? #=> false
|
207
|
+
# trace.enable #=> false (previous state)
|
208
|
+
# # trace is enabled
|
209
|
+
# trace.enabled? #=> true
|
210
|
+
# trace.enable #=> true (previous state)
|
211
|
+
# # trace is still enabled
|
212
|
+
#
|
213
|
+
# If a block is given, the trace will only be enabled within the scope of the
|
214
|
+
# block.
|
215
|
+
#
|
216
|
+
# trace.enabled?
|
217
|
+
# #=> false
|
218
|
+
#
|
219
|
+
# trace.enable do
|
220
|
+
# trace.enabled?
|
221
|
+
# # only enabled for this block
|
222
|
+
# end
|
223
|
+
#
|
224
|
+
# trace.enabled?
|
225
|
+
# #=> false
|
226
|
+
#
|
227
|
+
# `target`, `target_line` and `target_thread` parameters are used to limit
|
228
|
+
# tracing only to specified code objects. `target` should be a code object for
|
229
|
+
# which RubyVM::InstructionSequence.of will return an instruction sequence.
|
230
|
+
#
|
231
|
+
# t = TracePoint.new(:line) { |tp| p tp }
|
232
|
+
#
|
233
|
+
# def m1
|
234
|
+
# p 1
|
235
|
+
# end
|
236
|
+
#
|
237
|
+
# def m2
|
238
|
+
# p 2
|
239
|
+
# end
|
240
|
+
#
|
241
|
+
# t.enable(target: method(:m1))
|
242
|
+
#
|
243
|
+
# m1
|
244
|
+
# # prints #<TracePoint:line@test.rb:5 in `m1'>
|
245
|
+
# m2
|
246
|
+
# # prints nothing
|
247
|
+
#
|
248
|
+
# Note: You cannot access event hooks within the `enable` block.
|
249
|
+
#
|
250
|
+
# trace.enable { p tp.lineno }
|
251
|
+
# #=> RuntimeError: access from outside
|
252
|
+
#
|
60
253
|
def enable: () -> bool
|
61
254
|
| () { () -> void } -> void
|
62
255
|
|
63
256
|
# The current status of the trace
|
257
|
+
#
|
64
258
|
def enabled?: () -> bool
|
65
259
|
|
260
|
+
# Return a string containing a human-readable TracePoint status.
|
261
|
+
#
|
66
262
|
def inspect: () -> String
|
67
263
|
|
68
264
|
# Line number of the event
|
265
|
+
#
|
69
266
|
def lineno: () -> Integer
|
70
267
|
|
71
268
|
# Return the name at the definition of the method being called
|
269
|
+
#
|
72
270
|
def method_id: () -> Symbol
|
73
271
|
|
74
272
|
# Path of the file being run
|
273
|
+
#
|
75
274
|
def path: () -> String
|
76
275
|
|
77
276
|
# Value from exception raised on the `:raise` event
|
277
|
+
#
|
78
278
|
def raised_exception: () -> untyped
|
79
279
|
|
80
280
|
# Return value from `:return`, `c_return`, and `b_return` event
|
281
|
+
#
|
81
282
|
def return_value: () -> untyped
|
82
283
|
|
83
284
|
# Return the trace object during event
|
84
|
-
#
|
85
|
-
# Same as
|
86
|
-
#
|
87
|
-
#
|
88
|
-
# trace.binding.eval('self')
|
89
|
-
# ```
|
285
|
+
#
|
286
|
+
# Same as TracePoint#binding:
|
287
|
+
# trace.binding.eval('self')
|
288
|
+
#
|
90
289
|
def `self`: () -> Binding
|
91
290
|
end
|
@@ -1,64 +1,58 @@
|
|
1
|
-
# Ruby supports two forms of objectified methods.
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# :
|
46
|
-
#
|
47
|
-
# end
|
48
|
-
# t = Test.new
|
49
|
-
# t.test #=> :modified
|
50
|
-
# um.bind(t).call #=> :original
|
51
|
-
# ```
|
1
|
+
# Ruby supports two forms of objectified methods. Class Method is used to
|
2
|
+
# represent methods that are associated with a particular object: these method
|
3
|
+
# objects are bound to that object. Bound method objects for an object can be
|
4
|
+
# created using Object#method.
|
5
|
+
#
|
6
|
+
# Ruby also supports unbound methods; methods objects that are not associated
|
7
|
+
# with a particular object. These can be created either by calling
|
8
|
+
# Module#instance_method or by calling #unbind on a bound method object. The
|
9
|
+
# result of both of these is an UnboundMethod object.
|
10
|
+
#
|
11
|
+
# Unbound methods can only be called after they are bound to an object. That
|
12
|
+
# object must be a kind_of? the method's original class.
|
13
|
+
#
|
14
|
+
# class Square
|
15
|
+
# def area
|
16
|
+
# @side * @side
|
17
|
+
# end
|
18
|
+
# def initialize(side)
|
19
|
+
# @side = side
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# area_un = Square.instance_method(:area)
|
24
|
+
#
|
25
|
+
# s = Square.new(12)
|
26
|
+
# area = area_un.bind(s)
|
27
|
+
# area.call #=> 144
|
28
|
+
#
|
29
|
+
# Unbound methods are a reference to the method at the time it was objectified:
|
30
|
+
# subsequent changes to the underlying class will not affect the unbound method.
|
31
|
+
#
|
32
|
+
# class Test
|
33
|
+
# def test
|
34
|
+
# :original
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
# um = Test.instance_method(:test)
|
38
|
+
# class Test
|
39
|
+
# def test
|
40
|
+
# :modified
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
# t = Test.new
|
44
|
+
# t.test #=> :modified
|
45
|
+
# um.bind(t).call #=> :original
|
46
|
+
#
|
52
47
|
class UnboundMethod
|
53
|
-
# Returns an indication of the number of arguments accepted by a method.
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
# argument
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
48
|
+
# Returns an indication of the number of arguments accepted by a method. Returns
|
49
|
+
# a nonnegative integer for methods that take a fixed number of arguments. For
|
50
|
+
# Ruby methods that take a variable number of arguments, returns -n-1, where n
|
51
|
+
# is the number of required arguments. Keyword arguments will be considered as a
|
52
|
+
# single additional argument, that argument being mandatory if any keyword
|
53
|
+
# argument is mandatory. For methods written in C, returns -1 if the call takes
|
54
|
+
# a variable number of arguments.
|
55
|
+
#
|
62
56
|
# class C
|
63
57
|
# def one; end
|
64
58
|
# def two(a); end
|
@@ -82,78 +76,78 @@ class UnboundMethod
|
|
82
76
|
# c.method(:eight).arity #=> 1
|
83
77
|
# c.method(:nine).arity #=> 1
|
84
78
|
# c.method(:ten).arity #=> -2
|
85
|
-
#
|
79
|
+
#
|
86
80
|
# "cat".method(:size).arity #=> 0
|
87
81
|
# "cat".method(:replace).arity #=> 1
|
88
82
|
# "cat".method(:squeeze).arity #=> -1
|
89
83
|
# "cat".method(:count).arity #=> -1
|
84
|
+
#
|
90
85
|
def arity: () -> Integer
|
91
86
|
|
92
|
-
# Bind *umeth* to *obj
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
# ```
|
114
|
-
#
|
87
|
+
# Bind *umeth* to *obj*. If Klass was the class from which *umeth* was obtained,
|
88
|
+
# `obj.kind_of?(Klass)` must be true.
|
89
|
+
#
|
90
|
+
# class A
|
91
|
+
# def test
|
92
|
+
# puts "In test, class = #{self.class}"
|
93
|
+
# end
|
94
|
+
# end
|
95
|
+
# class B < A
|
96
|
+
# end
|
97
|
+
# class C < B
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# um = B.instance_method(:test)
|
101
|
+
# bm = um.bind(C.new)
|
102
|
+
# bm.call
|
103
|
+
# bm = um.bind(B.new)
|
104
|
+
# bm.call
|
105
|
+
# bm = um.bind(A.new)
|
106
|
+
# bm.call
|
107
|
+
#
|
115
108
|
# *produces:*
|
116
|
-
#
|
109
|
+
#
|
117
110
|
# In test, class = C
|
118
111
|
# In test, class = B
|
119
112
|
# prog.rb:16:in `bind': bind argument must be an instance of B (TypeError)
|
120
113
|
# from prog.rb:16
|
114
|
+
#
|
121
115
|
def bind: (untyped obj) -> Method
|
122
116
|
|
123
117
|
# Returns the name of the method.
|
118
|
+
#
|
124
119
|
def name: () -> Symbol
|
125
120
|
|
126
|
-
# Returns the class or module that defines the method. See also receiver.
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
# ```
|
121
|
+
# Returns the class or module that defines the method. See also Method#receiver.
|
122
|
+
#
|
123
|
+
# (1..3).method(:map).owner #=> Enumerable
|
124
|
+
#
|
131
125
|
def owner: () -> Module
|
132
126
|
|
133
127
|
# Returns the parameter information of this method.
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
# ```
|
128
|
+
#
|
129
|
+
# def foo(bar); end
|
130
|
+
# method(:foo).parameters #=> [[:req, :bar]]
|
131
|
+
#
|
132
|
+
# def foo(bar, baz, bat, &blk); end
|
133
|
+
# method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:req, :bat], [:block, :blk]]
|
134
|
+
#
|
135
|
+
# def foo(bar, *args); end
|
136
|
+
# method(:foo).parameters #=> [[:req, :bar], [:rest, :args]]
|
137
|
+
#
|
138
|
+
# def foo(bar, baz, *args, &blk); end
|
139
|
+
# method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:rest, :args], [:block, :blk]]
|
140
|
+
#
|
148
141
|
def parameters: () -> ::Array[[ Symbol, Symbol ]]
|
149
142
|
| () -> ::Array[[ Symbol ]]
|
150
143
|
|
151
|
-
# Returns the Ruby source filename and line number containing this method
|
152
|
-
#
|
144
|
+
# Returns the Ruby source filename and line number containing this method or nil
|
145
|
+
# if this method was not defined in Ruby (i.e. native).
|
146
|
+
#
|
153
147
|
def source_location: () -> [ String, Integer ]?
|
154
148
|
|
155
|
-
# Returns a
|
156
|
-
#
|
157
|
-
#
|
149
|
+
# Returns a Method of superclass which would be called when super is used or nil
|
150
|
+
# if there is no method on superclass.
|
151
|
+
#
|
158
152
|
def super_method: () -> UnboundMethod?
|
159
153
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Coverage provides coverage measurement feature for Ruby. This feature is
|
2
|
+
# experimental, so these APIs may be changed in future.
|
3
|
+
#
|
4
|
+
# # Usage
|
5
|
+
#
|
6
|
+
# 1. require "coverage"
|
7
|
+
# 2. do Coverage.start
|
8
|
+
# 3. require or load Ruby source file
|
9
|
+
# 4. Coverage.result will return a hash that contains filename as key and
|
10
|
+
# coverage array as value. A coverage array gives, for each line, the number
|
11
|
+
# of line execution by the interpreter. A `nil` value means coverage is
|
12
|
+
# disabled for this line (lines like `else` and `end`).
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# # Example
|
16
|
+
#
|
17
|
+
# [foo.rb]
|
18
|
+
# s = 0
|
19
|
+
# 10.times do |x|
|
20
|
+
# s += x
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# if s == 45
|
24
|
+
# p :ok
|
25
|
+
# else
|
26
|
+
# p :ng
|
27
|
+
# end
|
28
|
+
# [EOF]
|
29
|
+
#
|
30
|
+
# require "coverage"
|
31
|
+
# Coverage.start
|
32
|
+
# require "foo.rb"
|
33
|
+
# p Coverage.result #=> {"foo.rb"=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]}
|
34
|
+
#
|
35
|
+
module Coverage
|
36
|
+
def self.line_stub: () -> Array[Integer?]
|
37
|
+
|
38
|
+
# Returns a hash that contains filename as key and coverage array as value. This
|
39
|
+
# is the same as `Coverage.result(stop: false, clear: false)`.
|
40
|
+
#
|
41
|
+
# {
|
42
|
+
# "file.rb" => [1, 2, nil],
|
43
|
+
# ...
|
44
|
+
# }
|
45
|
+
#
|
46
|
+
def self.peek_result: () -> Hash[String, untyped]
|
47
|
+
|
48
|
+
# Returns a hash that contains filename as key and coverage array as value. If
|
49
|
+
# `clear` is true, it clears the counters to zero. If `stop` is true, it
|
50
|
+
# disables coverage measurement.
|
51
|
+
#
|
52
|
+
def self.result: (?stop: bool, ?clear: bool) -> Hash[String, untyped]
|
53
|
+
|
54
|
+
# Returns true if coverage stats are currently being collected (after
|
55
|
+
# Coverage.start call, but before Coverage.result call)
|
56
|
+
#
|
57
|
+
def self.running?: () -> bool
|
58
|
+
|
59
|
+
# Enables coverage measurement.
|
60
|
+
#
|
61
|
+
def self.start: (?lines: bool, ?branches: bool, ?methods: bool, ?oneshot_lines: bool) -> nil
|
62
|
+
end
|