steep 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/exe/rbs +1 -1
  4. data/lib/steep/annotation_parser.rb +4 -4
  5. data/lib/steep/ast/buffer.rb +11 -7
  6. data/lib/steep/ast/builtin.rb +8 -0
  7. data/lib/steep/ast/types/factory.rb +55 -55
  8. data/lib/steep/drivers/check.rb +20 -4
  9. data/lib/steep/drivers/langserver.rb +6 -1
  10. data/lib/steep/drivers/vendor.rb +2 -2
  11. data/lib/steep/project/completion_provider.rb +5 -11
  12. data/lib/steep/project/dsl.rb +14 -0
  13. data/lib/steep/project/file.rb +42 -46
  14. data/lib/steep/project/hover_content.rb +11 -5
  15. data/lib/steep/project/options.rb +25 -3
  16. data/lib/steep/project/target.rb +10 -4
  17. data/lib/steep/signature/errors.rb +1 -1
  18. data/lib/steep/signature/validator.rb +8 -8
  19. data/lib/steep/source.rb +1 -1
  20. data/lib/steep/type_construction.rb +987 -711
  21. data/lib/steep/type_inference/constant_env.rb +1 -1
  22. data/lib/steep/type_inference/context.rb +7 -3
  23. data/lib/steep/type_inference/context_array.rb +111 -0
  24. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  25. data/lib/steep/type_inference/logic.rb +130 -0
  26. data/lib/steep/type_inference/type_env.rb +5 -69
  27. data/lib/steep/typing.rb +79 -22
  28. data/lib/steep/version.rb +1 -1
  29. data/lib/steep.rb +6 -1
  30. data/smoke/alias/Steepfile +1 -0
  31. data/smoke/and/Steepfile +1 -0
  32. data/smoke/array/Steepfile +1 -0
  33. data/smoke/array/b.rb +0 -2
  34. data/smoke/block/Steepfile +1 -0
  35. data/smoke/case/Steepfile +1 -0
  36. data/smoke/class/Steepfile +1 -0
  37. data/smoke/const/Steepfile +1 -0
  38. data/smoke/dstr/Steepfile +1 -0
  39. data/smoke/ensure/Steepfile +1 -0
  40. data/smoke/enumerator/Steepfile +1 -0
  41. data/smoke/extension/Steepfile +1 -0
  42. data/smoke/extension/c.rb +1 -0
  43. data/smoke/hash/Steepfile +1 -0
  44. data/smoke/hello/Steepfile +1 -0
  45. data/smoke/if/Steepfile +1 -0
  46. data/smoke/if/a.rb +1 -1
  47. data/smoke/implements/Steepfile +1 -0
  48. data/smoke/initialize/Steepfile +1 -0
  49. data/smoke/integer/Steepfile +1 -0
  50. data/smoke/interface/Steepfile +1 -0
  51. data/smoke/kwbegin/Steepfile +1 -0
  52. data/smoke/lambda/Steepfile +1 -0
  53. data/smoke/literal/Steepfile +1 -0
  54. data/smoke/map/Steepfile +1 -0
  55. data/smoke/method/Steepfile +1 -0
  56. data/smoke/module/Steepfile +1 -0
  57. data/smoke/regexp/Steepfile +1 -0
  58. data/smoke/regression/Steepfile +1 -0
  59. data/smoke/rescue/Steepfile +1 -0
  60. data/smoke/rescue/a.rb +1 -1
  61. data/smoke/self/Steepfile +1 -0
  62. data/smoke/skip/Steepfile +1 -0
  63. data/smoke/stdout/Steepfile +1 -0
  64. data/smoke/super/Steepfile +1 -0
  65. data/smoke/type_case/Steepfile +1 -0
  66. data/smoke/yield/Steepfile +1 -0
  67. data/steep.gemspec +1 -1
  68. data/vendor/ruby-signature/.gitignore +2 -2
  69. data/vendor/ruby-signature/README.md +2 -2
  70. data/vendor/ruby-signature/Rakefile +2 -2
  71. data/vendor/ruby-signature/bin/annotate-with-rdoc +14 -13
  72. data/vendor/ruby-signature/bin/console +1 -1
  73. data/vendor/ruby-signature/bin/sort +7 -6
  74. data/vendor/ruby-signature/bin/test_runner.rb +0 -1
  75. data/vendor/ruby-signature/docs/CONTRIBUTING.md +1 -1
  76. data/vendor/ruby-signature/docs/sigs.md +3 -3
  77. data/vendor/ruby-signature/docs/stdlib.md +1 -1
  78. data/vendor/ruby-signature/docs/syntax.md +9 -9
  79. data/vendor/ruby-signature/exe/rbs +5 -1
  80. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +27 -0
  81. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +27 -0
  82. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +395 -0
  83. data/vendor/ruby-signature/lib/rbs/ast/members.rb +362 -0
  84. data/vendor/ruby-signature/lib/rbs/buffer.rb +50 -0
  85. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +55 -0
  86. data/vendor/ruby-signature/lib/rbs/cli.rb +558 -0
  87. data/vendor/ruby-signature/lib/rbs/constant.rb +26 -0
  88. data/vendor/ruby-signature/lib/rbs/constant_table.rb +150 -0
  89. data/vendor/ruby-signature/lib/rbs/definition.rb +170 -0
  90. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +919 -0
  91. data/vendor/ruby-signature/lib/rbs/environment.rb +281 -0
  92. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +136 -0
  93. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +124 -0
  94. data/vendor/ruby-signature/lib/rbs/errors.rb +187 -0
  95. data/vendor/ruby-signature/lib/rbs/location.rb +102 -0
  96. data/vendor/ruby-signature/lib/rbs/method_type.rb +123 -0
  97. data/vendor/ruby-signature/lib/rbs/namespace.rb +91 -0
  98. data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.rb +21 -23
  99. data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.y +18 -18
  100. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +553 -0
  101. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +587 -0
  102. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +381 -0
  103. data/vendor/ruby-signature/lib/rbs/substitution.rb +46 -0
  104. data/vendor/ruby-signature/lib/rbs/test/errors.rb +61 -0
  105. data/vendor/ruby-signature/lib/rbs/test/hook.rb +294 -0
  106. data/vendor/ruby-signature/lib/{ruby/signature → rbs}/test/setup.rb +7 -7
  107. data/vendor/ruby-signature/lib/rbs/test/spy.rb +325 -0
  108. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +183 -0
  109. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +254 -0
  110. data/vendor/ruby-signature/lib/rbs/test.rb +26 -0
  111. data/vendor/ruby-signature/lib/rbs/type_name.rb +70 -0
  112. data/vendor/ruby-signature/lib/rbs/types.rb +936 -0
  113. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +138 -0
  114. data/vendor/ruby-signature/lib/rbs/vendorer.rb +47 -0
  115. data/vendor/ruby-signature/lib/rbs/version.rb +3 -0
  116. data/vendor/ruby-signature/lib/rbs/writer.rb +269 -0
  117. data/vendor/ruby-signature/lib/rbs.rb +64 -0
  118. data/vendor/ruby-signature/lib/ruby/signature.rb +4 -61
  119. data/vendor/ruby-signature/{ruby-signature.gemspec → rbs.gemspec} +4 -4
  120. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +58 -1
  121. data/vendor/ruby-signature/stdlib/base64/base64.rbs +69 -13
  122. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +372 -0
  123. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +9 -0
  124. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +1 -7
  125. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +2 -1
  126. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +3 -2
  127. data/vendor/ruby-signature/stdlib/builtin/file.rbs +902 -302
  128. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +190 -68
  129. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +3 -6
  130. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +6 -4
  131. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +146 -120
  132. data/vendor/ruby-signature/stdlib/builtin/math.rbs +310 -7
  133. data/vendor/ruby-signature/stdlib/builtin/method.rbs +11 -8
  134. data/vendor/ruby-signature/stdlib/builtin/module.rbs +959 -103
  135. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +3 -0
  136. data/vendor/ruby-signature/stdlib/builtin/process.rbs +981 -108
  137. data/vendor/ruby-signature/stdlib/builtin/random.rbs +215 -41
  138. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +47 -0
  139. data/vendor/ruby-signature/stdlib/builtin/string.rbs +9 -2
  140. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +282 -11
  141. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +11 -13
  142. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +25 -29
  143. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +1 -1
  144. data/vendor/ruby-signature/stdlib/builtin/time.rbs +875 -567
  145. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +243 -44
  146. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +103 -109
  147. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +62 -0
  148. data/vendor/ruby-signature/stdlib/csv/csv.rbs +773 -0
  149. data/vendor/ruby-signature/stdlib/erb/erb.rbs +375 -1
  150. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -4
  151. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +247 -0
  152. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +1088 -16
  153. data/vendor/ruby-signature/stdlib/set/set.rbs +251 -27
  154. metadata +49 -44
  155. data/exe/ruby-signature +0 -3
  156. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  157. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  158. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  159. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  160. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  161. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  162. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  163. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
  164. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  165. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  166. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  167. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  168. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  169. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  170. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  171. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  172. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  173. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  174. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  175. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
  176. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  177. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  178. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  179. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  180. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  181. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
  182. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  183. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  184. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  185. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  186. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  187. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  188. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  189. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  190. 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
- # [TracePoint](TracePoint.downloaded.ruby_doc).
6
- #
7
- # The contents of the returned value are implementation specific. It may
8
- # be changed in future.
9
- #
10
- # This method is only for debugging
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
- def `defined_class`: () -> Module
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
- # ```ruby
29
- # trace.enabled? #=> true
30
- # trace.disable #=> true (previous status)
31
- # trace.enabled? #=> false
32
- # trace.disable #=> false
33
- # ```
34
- #
35
- # If a block is given, the trace will only be disable within the scope of
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
- # # only disabled for this block
45
- # end
46
- #
47
- # trace.enabled?
48
- # #=> true
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
- # ```ruby
54
- # trace.disable { p tp.lineno }
55
- # #=> RuntimeError: access from outside
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 [\#binding](TracePoint.downloaded.ruby_doc#method-i-binding):
86
- #
87
- # ```ruby
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
- # [Class](https://ruby-doc.org/core-2.6.3/Class.html) `Method` is used to
3
- # represent methods that are associated with a particular object: these
4
- # method objects are bound to that object. Bound method objects for an
5
- # object can be created using `Object#method` .
6
- #
7
- # Ruby also supports unbound methods; methods objects that are not
8
- # associated with a particular object. These can be created either by
9
- # calling `Module#instance_method` or by calling `unbind` on a bound
10
- # method object. The result of both of these is an `UnboundMethod` object.
11
- #
12
- # Unbound methods can only be called after they are bound to an object.
13
- # That object must be a kind\_of? the method's original class.
14
- #
15
- # ```ruby
16
- # class Square
17
- # def area
18
- # @side * @side
19
- # end
20
- # def initialize(side)
21
- # @side = side
22
- # end
23
- # end
24
- #
25
- # area_un = Square.instance_method(:area)
26
- #
27
- # s = Square.new(12)
28
- # area = area_un.bind(s)
29
- # area.call #=> 144
30
- # ```
31
- #
32
- # Unbound methods are a reference to the method at the time it was
33
- # objectified: subsequent changes to the underlying class will not affect
34
- # the unbound method.
35
- #
36
- # ```ruby
37
- # class Test
38
- # def test
39
- # :original
40
- # end
41
- # end
42
- # um = Test.instance_method(:test)
43
- # class Test
44
- # def test
45
- # :modified
46
- # end
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
- # Returns a nonnegative integer for methods that take a fixed number of
55
- # arguments. For Ruby methods that take a variable number of arguments,
56
- # returns -n-1, where n is the number of required arguments. Keyword
57
- # arguments will be considered as a single additional argument, that
58
- # argument being mandatory if any keyword argument is mandatory. For
59
- # methods written in C, returns -1 if the call takes a variable number of
60
- # arguments.
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* . If `Klass` was the class from which *umeth* was
93
- # obtained, `obj.kind_of?(Klass)` must be true.
94
- #
95
- # ```ruby
96
- # class A
97
- # def test
98
- # puts "In test, class = #{self.class}"
99
- # end
100
- # end
101
- # class B < A
102
- # end
103
- # class C < B
104
- # end
105
- #
106
- # um = B.instance_method(:test)
107
- # bm = um.bind(C.new)
108
- # bm.call
109
- # bm = um.bind(B.new)
110
- # bm.call
111
- # bm = um.bind(A.new)
112
- # bm.call
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
- # ```ruby
129
- # (1..3).method(:map).owner #=> Enumerable
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
- # ```ruby
136
- # def foo(bar); end
137
- # method(:foo).parameters #=> [[:req, :bar]]
138
- #
139
- # def foo(bar, baz, bat, &blk); end
140
- # method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:req, :bat], [:block, :blk]]
141
- #
142
- # def foo(bar, *args); end
143
- # method(:foo).parameters #=> [[:req, :bar], [:rest, :args]]
144
- #
145
- # def foo(bar, baz, *args, &blk); end
146
- # method(:foo).parameters #=> [[:req, :bar], [:req, :baz], [:rest, :args], [:block, :blk]]
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
- # or nil if this method was not defined in Ruby (i.e. native).
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 [Method](https://ruby-doc.org/core-2.6.3/Method.html) of
156
- # superclass which would be called when super is used or nil if there is
157
- # no method on superclass.
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