steep 0.13.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +28 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep.rb +33 -1
  9. data/lib/steep/annotation_parser.rb +4 -4
  10. data/lib/steep/ast/buffer.rb +11 -7
  11. data/lib/steep/ast/builtin.rb +8 -0
  12. data/lib/steep/ast/types/factory.rb +124 -89
  13. data/lib/steep/cli.rb +16 -1
  14. data/lib/steep/drivers/annotations.rb +1 -1
  15. data/lib/steep/drivers/check.rb +20 -4
  16. data/lib/steep/drivers/init.rb +5 -5
  17. data/lib/steep/drivers/langserver.rb +13 -287
  18. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  19. data/lib/steep/drivers/vendor.rb +2 -2
  20. data/lib/steep/drivers/watch.rb +97 -85
  21. data/lib/steep/drivers/worker.rb +51 -0
  22. data/lib/steep/project.rb +9 -5
  23. data/lib/steep/project/completion_provider.rb +298 -0
  24. data/lib/steep/project/dsl.rb +14 -0
  25. data/lib/steep/project/file.rb +54 -47
  26. data/lib/steep/project/hover_content.rb +17 -8
  27. data/lib/steep/project/options.rb +25 -3
  28. data/lib/steep/project/target.rb +40 -24
  29. data/lib/steep/server/base_worker.rb +56 -0
  30. data/lib/steep/server/code_worker.rb +151 -0
  31. data/lib/steep/server/interaction_worker.rb +281 -0
  32. data/lib/steep/server/master.rb +196 -0
  33. data/lib/steep/server/signature_worker.rb +148 -0
  34. data/lib/steep/server/utils.rb +36 -0
  35. data/lib/steep/server/worker_process.rb +62 -0
  36. data/lib/steep/signature/errors.rb +1 -1
  37. data/lib/steep/signature/validator.rb +13 -13
  38. data/lib/steep/source.rb +1 -1
  39. data/lib/steep/type_construction.rb +1004 -727
  40. data/lib/steep/type_inference/constant_env.rb +3 -11
  41. data/lib/steep/type_inference/context.rb +8 -3
  42. data/lib/steep/type_inference/context_array.rb +111 -0
  43. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  44. data/lib/steep/type_inference/logic.rb +130 -0
  45. data/lib/steep/type_inference/type_env.rb +5 -69
  46. data/lib/steep/typing.rb +91 -23
  47. data/lib/steep/version.rb +1 -1
  48. data/smoke/alias/Steepfile +1 -0
  49. data/smoke/alias/a.rb +1 -1
  50. data/smoke/and/Steepfile +1 -0
  51. data/smoke/array/Steepfile +1 -0
  52. data/smoke/array/b.rb +0 -2
  53. data/smoke/block/Steepfile +1 -0
  54. data/smoke/case/Steepfile +1 -0
  55. data/smoke/class/Steepfile +1 -0
  56. data/smoke/const/Steepfile +1 -0
  57. data/smoke/dstr/Steepfile +1 -0
  58. data/smoke/ensure/Steepfile +1 -0
  59. data/smoke/enumerator/Steepfile +1 -0
  60. data/smoke/extension/Steepfile +1 -0
  61. data/smoke/extension/c.rb +1 -0
  62. data/smoke/hash/Steepfile +1 -0
  63. data/smoke/hello/Steepfile +1 -0
  64. data/smoke/if/Steepfile +1 -0
  65. data/smoke/if/a.rb +1 -1
  66. data/smoke/implements/Steepfile +1 -0
  67. data/smoke/initialize/Steepfile +1 -0
  68. data/smoke/integer/Steepfile +1 -0
  69. data/smoke/interface/Steepfile +1 -0
  70. data/smoke/kwbegin/Steepfile +1 -0
  71. data/smoke/lambda/Steepfile +1 -0
  72. data/smoke/literal/Steepfile +1 -0
  73. data/smoke/map/Steepfile +1 -0
  74. data/smoke/method/Steepfile +1 -0
  75. data/smoke/module/Steepfile +1 -0
  76. data/smoke/regexp/Steepfile +1 -0
  77. data/smoke/regexp/b.rb +4 -4
  78. data/smoke/regression/Steepfile +1 -0
  79. data/smoke/rescue/Steepfile +1 -0
  80. data/smoke/rescue/a.rb +1 -1
  81. data/smoke/self/Steepfile +1 -0
  82. data/smoke/skip/Steepfile +1 -0
  83. data/smoke/stdout/Steepfile +1 -0
  84. data/smoke/super/Steepfile +1 -0
  85. data/smoke/type_case/Steepfile +1 -0
  86. data/smoke/yield/Steepfile +1 -0
  87. data/steep.gemspec +8 -8
  88. metadata +38 -138
  89. data/exe/rbs +0 -3
  90. data/exe/ruby-signature +0 -3
  91. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  92. data/vendor/ruby-signature/.gitignore +0 -12
  93. data/vendor/ruby-signature/.rubocop.yml +0 -15
  94. data/vendor/ruby-signature/BSDL +0 -22
  95. data/vendor/ruby-signature/COPYING +0 -56
  96. data/vendor/ruby-signature/Gemfile +0 -6
  97. data/vendor/ruby-signature/README.md +0 -93
  98. data/vendor/ruby-signature/Rakefile +0 -66
  99. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
  100. data/vendor/ruby-signature/bin/console +0 -14
  101. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  102. data/vendor/ruby-signature/bin/setup +0 -10
  103. data/vendor/ruby-signature/bin/sort +0 -88
  104. data/vendor/ruby-signature/bin/test_runner.rb +0 -17
  105. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  106. data/vendor/ruby-signature/docs/sigs.md +0 -148
  107. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  108. data/vendor/ruby-signature/docs/syntax.md +0 -528
  109. data/vendor/ruby-signature/exe/rbs +0 -3
  110. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  111. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
  112. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  113. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  114. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  115. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  116. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  117. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  118. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
  119. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  120. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  121. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  122. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  123. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  124. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  125. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  126. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  127. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  128. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  129. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  130. data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
  131. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
  132. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  133. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  134. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  135. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  136. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  137. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  138. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
  139. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
  140. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  141. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  142. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  143. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  144. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  145. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  146. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  147. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
  148. data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
  149. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
  150. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
  151. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  152. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  153. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  154. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
  155. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  156. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  157. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  158. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  159. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  160. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  161. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
  162. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
  163. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  164. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  165. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  166. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  167. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
  168. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  169. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  170. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  171. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
  172. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  173. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  174. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
  175. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  176. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
  177. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  178. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
  179. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
  180. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
  181. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
  182. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
  183. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
  184. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  185. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  186. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  187. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
  188. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
  189. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
  190. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  191. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  192. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
  193. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
  194. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  195. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  196. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
  197. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
  198. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  199. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
  200. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
  201. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  202. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
  203. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
  204. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  205. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
  206. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  207. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
  208. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
  209. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
  210. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  211. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  212. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  213. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
  214. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,824 +0,0 @@
1
- # Object is the default root of all Ruby objects. Object inherits from
2
- # BasicObject which allows creating alternate object hierarchies. Methods on
3
- # Object are available to all classes unless explicitly overridden.
4
- #
5
- # Object mixes in the Kernel module, making the built-in kernel functions
6
- # globally accessible. Although the instance methods of Object are defined by
7
- # the Kernel module, we have chosen to document them here for clarity.
8
- #
9
- # When referencing constants in classes inheriting from Object you do not need
10
- # to use the full namespace. For example, referencing `File` inside `YourClass`
11
- # will find the top-level File class.
12
- #
13
- # In the descriptions of Object's methods, the parameter *symbol* refers to a
14
- # symbol, which is either a quoted string or a Symbol (such as `:name`).
15
- #
16
- class Object < BasicObject
17
- include Kernel
18
-
19
- # Returns true if two objects do not match (using the *=~* method), otherwise
20
- # false.
21
- #
22
- def !~: (untyped) -> bool
23
-
24
- # Returns 0 if `obj` and `other` are the same object or `obj == other`,
25
- # otherwise nil.
26
- #
27
- # The `<=>` is used by various methods to compare objects, for example
28
- # Enumerable#sort, Enumerable#max etc.
29
- #
30
- # Your implementation of `<=>` should return one of the following values: -1, 0,
31
- # 1 or nil. -1 means self is smaller than other. 0 means self is equal to other.
32
- # 1 means self is bigger than other. Nil means the two values could not be
33
- # compared.
34
- #
35
- # When you define `<=>`, you can include Comparable to gain the methods `<=`,
36
- # `<`, `==`, `>=`, `>` and `between?`.
37
- #
38
- def <=>: (untyped) -> Integer?
39
-
40
- # Case Equality -- For class Object, effectively the same as calling `#==`, but
41
- # typically overridden by descendants to provide meaningful semantics in `case`
42
- # statements.
43
- #
44
- def ===: (untyped) -> bool
45
-
46
- # This method is deprecated.
47
- #
48
- # This is not only unuseful but also troublesome because it may hide a type
49
- # error.
50
- #
51
- def =~: (untyped) -> bool
52
-
53
- # Returns the class of *obj*. This method must always be called with an explicit
54
- # receiver, as `class` is also a reserved word in Ruby.
55
- #
56
- # 1.class #=> Integer
57
- # self.class #=> Object
58
- #
59
- def `class`: () -> untyped
60
-
61
- # Produces a shallow copy of *obj*---the instance variables of *obj* are copied,
62
- # but not the objects they reference. `clone` copies the frozen (unless :freeze
63
- # keyword argument is given with a false value) and tainted state of *obj*. See
64
- # also the discussion under `Object#dup`.
65
- #
66
- # class Klass
67
- # attr_accessor :str
68
- # end
69
- # s1 = Klass.new #=> #<Klass:0x401b3a38>
70
- # s1.str = "Hello" #=> "Hello"
71
- # s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello">
72
- # s2.str[1,4] = "i" #=> "i"
73
- # s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
74
- # s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
75
- #
76
- # This method may have class-specific behavior. If so, that behavior will be
77
- # documented under the #`initialize_copy` method of the class.
78
- #
79
- def clone: (?freeze: bool) -> self
80
-
81
- # Defines a singleton method in the receiver. The *method* parameter can be a
82
- # `Proc`, a `Method` or an `UnboundMethod` object. If a block is specified, it
83
- # is used as the method body.
84
- #
85
- # class A
86
- # class << self
87
- # def class_name
88
- # to_s
89
- # end
90
- # end
91
- # end
92
- # A.define_singleton_method(:who_am_i) do
93
- # "I am: #{class_name}"
94
- # end
95
- # A.who_am_i # ==> "I am: A"
96
- #
97
- # guy = "Bob"
98
- # guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
99
- # guy.hello #=> "Bob: Hello there!"
100
- #
101
- def define_singleton_method: (Symbol, Method | UnboundMethod) -> Symbol
102
- | (Symbol) { (*untyped) -> untyped } -> Symbol
103
-
104
- # Prints *obj* on the given port (default `$>`). Equivalent to:
105
- #
106
- # def display(port=$>)
107
- # port.write self
108
- # nil
109
- # end
110
- #
111
- # For example:
112
- #
113
- # 1.display
114
- # "cat".display
115
- # [ 4, 5, 6 ].display
116
- # puts
117
- #
118
- # *produces:*
119
- #
120
- # 1cat[4, 5, 6]
121
- #
122
- def display: (?_Writeable port) -> void
123
-
124
- # Produces a shallow copy of *obj*---the instance variables of *obj* are copied,
125
- # but not the objects they reference. `dup` copies the tainted state of *obj*.
126
- #
127
- # This method may have class-specific behavior. If so, that behavior will be
128
- # documented under the #`initialize_copy` method of the class.
129
- #
130
- # ### on dup vs clone
131
- #
132
- # In general, `clone` and `dup` may have different semantics in descendant
133
- # classes. While `clone` is used to duplicate an object, including its internal
134
- # state, `dup` typically uses the class of the descendant object to create the
135
- # new instance.
136
- #
137
- # When using #dup, any modules that the object has been extended with will not
138
- # be copied.
139
- #
140
- # class Klass
141
- # attr_accessor :str
142
- # end
143
- #
144
- # module Foo
145
- # def foo; 'foo'; end
146
- # end
147
- #
148
- # s1 = Klass.new #=> #<Klass:0x401b3a38>
149
- # s1.extend(Foo) #=> #<Klass:0x401b3a38>
150
- # s1.foo #=> "foo"
151
- #
152
- # s2 = s1.clone #=> #<Klass:0x401b3a38>
153
- # s2.foo #=> "foo"
154
- #
155
- # s3 = s1.dup #=> #<Klass:0x401b3a38>
156
- # s3.foo #=> NoMethodError: undefined method `foo' for #<Klass:0x401b3a38>
157
- #
158
- def dup: () -> self
159
-
160
- # Creates a new Enumerator which will enumerate by calling `method` on `obj`,
161
- # passing `args` if any.
162
- #
163
- # If a block is given, it will be used to calculate the size of the enumerator
164
- # without the need to iterate it (see Enumerator#size).
165
- #
166
- # ### Examples
167
- #
168
- # str = "xyz"
169
- #
170
- # enum = str.enum_for(:each_byte)
171
- # enum.each { |b| puts b }
172
- # # => 120
173
- # # => 121
174
- # # => 122
175
- #
176
- # # protect an array from being modified by some_method
177
- # a = [1, 2, 3]
178
- # some_method(a.to_enum)
179
- #
180
- # It is typical to call to_enum when defining methods for a generic Enumerable,
181
- # in case no block is passed.
182
- #
183
- # Here is such an example, with parameter passing and a sizing block:
184
- #
185
- # module Enumerable
186
- # # a generic method to repeat the values of any enumerable
187
- # def repeat(n)
188
- # raise ArgumentError, "#{n} is negative!" if n < 0
189
- # unless block_given?
190
- # return to_enum(__method__, n) do # __method__ is :repeat here
191
- # sz = size # Call size and multiply by n...
192
- # sz * n if sz # but return nil if size itself is nil
193
- # end
194
- # end
195
- # each do |*val|
196
- # n.times { yield *val }
197
- # end
198
- # end
199
- # end
200
- #
201
- # %i[hello world].repeat(2) { |w| puts w }
202
- # # => Prints 'hello', 'hello', 'world', 'world'
203
- # enum = (1..14).repeat(3)
204
- # # => returns an Enumerator when called without a block
205
- # enum.first(4) # => [1, 1, 1, 2]
206
- # enum.size # => 42
207
- #
208
- def enum_for: (Symbol method, *untyped args) ?{ (*untyped args) -> Integer } -> Enumerator[untyped, untyped]
209
- | (*untyped args) ?{ (*untyped args) -> Integer } -> Enumerator[untyped, untyped]
210
-
211
- # Creates a new Enumerator which will enumerate by calling `method` on `obj`,
212
- # passing `args` if any.
213
- #
214
- # If a block is given, it will be used to calculate the size of the enumerator
215
- # without the need to iterate it (see Enumerator#size).
216
- #
217
- # ### Examples
218
- #
219
- # str = "xyz"
220
- #
221
- # enum = str.enum_for(:each_byte)
222
- # enum.each { |b| puts b }
223
- # # => 120
224
- # # => 121
225
- # # => 122
226
- #
227
- # # protect an array from being modified by some_method
228
- # a = [1, 2, 3]
229
- # some_method(a.to_enum)
230
- #
231
- # It is typical to call to_enum when defining methods for a generic Enumerable,
232
- # in case no block is passed.
233
- #
234
- # Here is such an example, with parameter passing and a sizing block:
235
- #
236
- # module Enumerable
237
- # # a generic method to repeat the values of any enumerable
238
- # def repeat(n)
239
- # raise ArgumentError, "#{n} is negative!" if n < 0
240
- # unless block_given?
241
- # return to_enum(__method__, n) do # __method__ is :repeat here
242
- # sz = size # Call size and multiply by n...
243
- # sz * n if sz # but return nil if size itself is nil
244
- # end
245
- # end
246
- # each do |*val|
247
- # n.times { yield *val }
248
- # end
249
- # end
250
- # end
251
- #
252
- # %i[hello world].repeat(2) { |w| puts w }
253
- # # => Prints 'hello', 'hello', 'world', 'world'
254
- # enum = (1..14).repeat(3)
255
- # # => returns an Enumerator when called without a block
256
- # enum.first(4) # => [1, 1, 1, 2]
257
- # enum.size # => 42
258
- #
259
- alias to_enum enum_for
260
-
261
- # Equality --- At the `Object` level, `==` returns `true` only if `obj` and
262
- # `other` are the same object. Typically, this method is overridden in
263
- # descendant classes to provide class-specific meaning.
264
- #
265
- # Unlike `==`, the `equal?` method should never be overridden by subclasses as
266
- # it is used to determine object identity (that is, `a.equal?(b)` if and only if
267
- # `a` is the same object as `b`):
268
- #
269
- # obj = "a"
270
- # other = obj.dup
271
- #
272
- # obj == other #=> true
273
- # obj.equal? other #=> false
274
- # obj.equal? obj #=> true
275
- #
276
- # The `eql?` method returns `true` if `obj` and `other` refer to the same hash
277
- # key. This is used by Hash to test members for equality. For objects of class
278
- # `Object`, `eql?` is synonymous with `==`. Subclasses normally continue this
279
- # tradition by aliasing `eql?` to their overridden `==` method, but there are
280
- # exceptions. `Numeric` types, for example, perform type conversion across
281
- # `==`, but not across `eql?`, so:
282
- #
283
- # 1 == 1.0 #=> true
284
- # 1.eql? 1.0 #=> false
285
- #
286
- def eql?: (untyped) -> bool
287
-
288
- # Adds to *obj* the instance methods from each module given as a parameter.
289
- #
290
- # module Mod
291
- # def hello
292
- # "Hello from Mod.\n"
293
- # end
294
- # end
295
- #
296
- # class Klass
297
- # def hello
298
- # "Hello from Klass.\n"
299
- # end
300
- # end
301
- #
302
- # k = Klass.new
303
- # k.hello #=> "Hello from Klass.\n"
304
- # k.extend(Mod) #=> #<Klass:0x401b3bc8>
305
- # k.hello #=> "Hello from Mod.\n"
306
- #
307
- def `extend`: (*Module) -> self
308
-
309
- # Prevents further modifications to *obj*. A `RuntimeError` will be raised if
310
- # modification is attempted. There is no way to unfreeze a frozen object. See
311
- # also `Object#frozen?`.
312
- #
313
- # This method returns self.
314
- #
315
- # a = [ "a", "b", "c" ]
316
- # a.freeze
317
- # a << "z"
318
- #
319
- # *produces:*
320
- #
321
- # prog.rb:3:in `<<': can't modify frozen Array (FrozenError)
322
- # from prog.rb:3
323
- #
324
- # Objects of the following classes are always frozen: Integer, Float, Symbol.
325
- #
326
- def freeze: () -> self
327
-
328
- # Returns the freeze status of *obj*.
329
- #
330
- # a = [ "a", "b", "c" ]
331
- # a.freeze #=> ["a", "b", "c"]
332
- # a.frozen? #=> true
333
- #
334
- def frozen?: () -> bool
335
-
336
- def hash: () -> Integer
337
-
338
- # Returns a string containing a human-readable representation of *obj*. The
339
- # default `inspect` shows the object's class name, an encoding of the object id,
340
- # and a list of the instance variables and their values (by calling #inspect on
341
- # each of them). User defined classes should override this method to provide a
342
- # better representation of *obj*. When overriding this method, it should return
343
- # a string whose encoding is compatible with the default external encoding.
344
- #
345
- # [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]"
346
- # Time.new.inspect #=> "2008-03-08 19:43:39 +0900"
347
- #
348
- # class Foo
349
- # end
350
- # Foo.new.inspect #=> "#<Foo:0x0300c868>"
351
- #
352
- # class Bar
353
- # def initialize
354
- # @bar = 1
355
- # end
356
- # end
357
- # Bar.new.inspect #=> "#<Bar:0x0300c868 @bar=1>"
358
- #
359
- def inspect: () -> String
360
-
361
- # Returns `true` if *obj* is an instance of the given class. See also
362
- # `Object#kind_of?`.
363
- #
364
- # class A; end
365
- # class B < A; end
366
- # class C < B; end
367
- #
368
- # b = B.new
369
- # b.instance_of? A #=> false
370
- # b.instance_of? B #=> true
371
- # b.instance_of? C #=> false
372
- #
373
- def instance_of?: (Module) -> bool
374
-
375
- # Returns `true` if the given instance variable is defined in *obj*. String
376
- # arguments are converted to symbols.
377
- #
378
- # class Fred
379
- # def initialize(p1, p2)
380
- # @a, @b = p1, p2
381
- # end
382
- # end
383
- # fred = Fred.new('cat', 99)
384
- # fred.instance_variable_defined?(:@a) #=> true
385
- # fred.instance_variable_defined?("@b") #=> true
386
- # fred.instance_variable_defined?("@c") #=> false
387
- #
388
- def instance_variable_defined?: (String | Symbol var) -> bool
389
-
390
- # Returns the value of the given instance variable, or nil if the instance
391
- # variable is not set. The `@` part of the variable name should be included for
392
- # regular instance variables. Throws a `NameError` exception if the supplied
393
- # symbol is not valid as an instance variable name. String arguments are
394
- # converted to symbols.
395
- #
396
- # class Fred
397
- # def initialize(p1, p2)
398
- # @a, @b = p1, p2
399
- # end
400
- # end
401
- # fred = Fred.new('cat', 99)
402
- # fred.instance_variable_get(:@a) #=> "cat"
403
- # fred.instance_variable_get("@b") #=> 99
404
- #
405
- def instance_variable_get: (String | Symbol var) -> untyped
406
-
407
- # Sets the instance variable named by *symbol* to the given object, thereby
408
- # frustrating the efforts of the class's author to attempt to provide proper
409
- # encapsulation. The variable does not have to exist prior to this call. If the
410
- # instance variable name is passed as a string, that string is converted to a
411
- # symbol.
412
- #
413
- # class Fred
414
- # def initialize(p1, p2)
415
- # @a, @b = p1, p2
416
- # end
417
- # end
418
- # fred = Fred.new('cat', 99)
419
- # fred.instance_variable_set(:@a, 'dog') #=> "dog"
420
- # fred.instance_variable_set(:@c, 'cat') #=> "cat"
421
- # fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
422
- #
423
- def instance_variable_set: [X] (String | Symbol var, X value) -> X
424
-
425
- # Returns an array of instance variable names for the receiver. Note that simply
426
- # defining an accessor does not create the corresponding instance variable.
427
- #
428
- # class Fred
429
- # attr_accessor :a1
430
- # def initialize
431
- # @iv = 3
432
- # end
433
- # end
434
- # Fred.new.instance_variables #=> [:@iv]
435
- #
436
- def instance_variables: () -> Array[Symbol]
437
-
438
- # Returns `true` if *class* is the class of *obj*, or if *class* is one of the
439
- # superclasses of *obj* or modules included in *obj*.
440
- #
441
- # module M; end
442
- # class A
443
- # include M
444
- # end
445
- # class B < A; end
446
- # class C < B; end
447
- #
448
- # b = B.new
449
- # b.is_a? A #=> true
450
- # b.is_a? B #=> true
451
- # b.is_a? C #=> false
452
- # b.is_a? M #=> true
453
- #
454
- # b.kind_of? A #=> true
455
- # b.kind_of? B #=> true
456
- # b.kind_of? C #=> false
457
- # b.kind_of? M #=> true
458
- #
459
- def is_a?: (Module) -> bool
460
-
461
- # Returns `true` if *class* is the class of *obj*, or if *class* is one of the
462
- # superclasses of *obj* or modules included in *obj*.
463
- #
464
- # module M; end
465
- # class A
466
- # include M
467
- # end
468
- # class B < A; end
469
- # class C < B; end
470
- #
471
- # b = B.new
472
- # b.is_a? A #=> true
473
- # b.is_a? B #=> true
474
- # b.is_a? C #=> false
475
- # b.is_a? M #=> true
476
- #
477
- # b.kind_of? A #=> true
478
- # b.kind_of? B #=> true
479
- # b.kind_of? C #=> false
480
- # b.kind_of? M #=> true
481
- #
482
- alias kind_of? is_a?
483
-
484
- # Returns the receiver.
485
- #
486
- # string = "my string"
487
- # string.itself.object_id == string.object_id #=> true
488
- #
489
- def `itself`: () -> self
490
-
491
- # Looks up the named method as a receiver in *obj*, returning a `Method` object
492
- # (or raising `NameError`). The `Method` object acts as a closure in *obj*'s
493
- # object instance, so instance variables and the value of `self` remain
494
- # available.
495
- #
496
- # class Demo
497
- # def initialize(n)
498
- # @iv = n
499
- # end
500
- # def hello()
501
- # "Hello, @iv = #{@iv}"
502
- # end
503
- # end
504
- #
505
- # k = Demo.new(99)
506
- # m = k.method(:hello)
507
- # m.call #=> "Hello, @iv = 99"
508
- #
509
- # l = Demo.new('Fred')
510
- # m = l.method("hello")
511
- # m.call #=> "Hello, @iv = Fred"
512
- #
513
- # Note that `Method` implements `to_proc` method, which means it can be used
514
- # with iterators.
515
- #
516
- # [ 1, 2, 3 ].each(&method(:puts)) # => prints 3 lines to stdout
517
- #
518
- # out = File.open('test.txt', 'w')
519
- # [ 1, 2, 3 ].each(&out.method(:puts)) # => prints 3 lines to file
520
- #
521
- # require 'date'
522
- # %w[2017-03-01 2017-03-02].collect(&Date.method(:parse))
523
- # #=> [#<Date: 2017-03-01 ((2457814j,0s,0n),+0s,2299161j)>, #<Date: 2017-03-02 ((2457815j,0s,0n),+0s,2299161j)>]
524
- #
525
- def method: (String | Symbol name) -> Method
526
-
527
- # Returns a list of the names of public and protected methods of *obj*. This
528
- # will include all the methods accessible in *obj*'s ancestors. If the optional
529
- # parameter is `false`, it returns an array of *obj<i>'s public and protected
530
- # singleton methods, the array will not include methods in modules included in
531
- # <i>obj*.
532
- #
533
- # class Klass
534
- # def klass_method()
535
- # end
536
- # end
537
- # k = Klass.new
538
- # k.methods[0..9] #=> [:klass_method, :nil?, :===,
539
- # # :==~, :!, :eql?
540
- # # :hash, :<=>, :class, :singleton_class]
541
- # k.methods.length #=> 56
542
- #
543
- # k.methods(false) #=> []
544
- # def k.singleton_method; end
545
- # k.methods(false) #=> [:singleton_method]
546
- #
547
- # module M123; def m123; end end
548
- # k.extend M123
549
- # k.methods(false) #=> [:singleton_method]
550
- #
551
- def methods: () -> Array[Symbol]
552
-
553
- # Only the object *nil* responds `true` to `nil?`.
554
- #
555
- # Object.new.nil? #=> false
556
- # nil.nil? #=> true
557
- #
558
- def `nil?`: () -> bool
559
-
560
- # Returns an integer identifier for `obj`.
561
- #
562
- # The same number will be returned on all calls to `object_id` for a given
563
- # object, and no two active objects will share an id.
564
- #
565
- # Note: that some objects of builtin classes are reused for optimization. This
566
- # is the case for immediate values and frozen string literals.
567
- #
568
- # Immediate values are not passed by reference but are passed by value: `nil`,
569
- # `true`, `false`, Fixnums, Symbols, and some Floats.
570
- #
571
- # Object.new.object_id == Object.new.object_id # => false
572
- # (21 * 2).object_id == (21 * 2).object_id # => true
573
- # "hello".object_id == "hello".object_id # => false
574
- # "hi".freeze.object_id == "hi".freeze.object_id # => true
575
- #
576
- def object_id: () -> Integer
577
-
578
- # Returns the list of private methods accessible to *obj*. If the *all*
579
- # parameter is set to `false`, only those methods in the receiver will be
580
- # listed.
581
- #
582
- def private_methods: () -> Array[Symbol]
583
-
584
- # Returns the list of protected methods accessible to *obj*. If the *all*
585
- # parameter is set to `false`, only those methods in the receiver will be
586
- # listed.
587
- #
588
- def protected_methods: () -> Array[Symbol]
589
-
590
- # Similar to *method*, searches public method only.
591
- #
592
- def public_method: (name name) -> Method
593
-
594
- # Invokes the method identified by *symbol*, passing it any arguments specified.
595
- # Unlike send, public_send calls public methods only. When the method is
596
- # identified by a string, the string is converted to a symbol.
597
- #
598
- # 1.public_send(:puts, "hello") # causes NoMethodError
599
- #
600
- def `public_send`: (name name, *untyped args) ?{ (*untyped) -> untyped } -> untyped
601
-
602
- # Removes the named instance variable from *obj*, returning that variable's
603
- # value. String arguments are converted to symbols.
604
- #
605
- # class Dummy
606
- # attr_reader :var
607
- # def initialize
608
- # @var = 99
609
- # end
610
- # def remove
611
- # remove_instance_variable(:@var)
612
- # end
613
- # end
614
- # d = Dummy.new
615
- # d.var #=> 99
616
- # d.remove #=> 99
617
- # d.var #=> nil
618
- #
619
- def remove_instance_variable: (name name) -> untyped
620
-
621
- # Returns `true` if *obj* responds to the given method. Private and protected
622
- # methods are included in the search only if the optional second parameter
623
- # evaluates to `true`.
624
- #
625
- # If the method is not implemented, as Process.fork on Windows, File.lchmod on
626
- # GNU/Linux, etc., false is returned.
627
- #
628
- # If the method is not defined, `respond_to_missing?` method is called and the
629
- # result is returned.
630
- #
631
- # When the method name parameter is given as a string, the string is converted
632
- # to a symbol.
633
- #
634
- def respond_to?: (name name, ?bool include_all) -> bool
635
-
636
- # Invokes the method identified by *symbol*, passing it any arguments specified.
637
- # You can use `__send__` if the name `send` clashes with an existing method in
638
- # *obj*. When the method is identified by a string, the string is converted to a
639
- # symbol.
640
- #
641
- # class Klass
642
- # def hello(*args)
643
- # "Hello " + args.join(' ')
644
- # end
645
- # end
646
- # k = Klass.new
647
- # k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
648
- #
649
- def `send`: (name name, *untyped args) ?{ (*untyped) -> untyped } -> untyped
650
-
651
- # Returns the singleton class of *obj*. This method creates a new singleton
652
- # class if *obj* does not have one.
653
- #
654
- # If *obj* is `nil`, `true`, or `false`, it returns NilClass, TrueClass, or
655
- # FalseClass, respectively. If *obj* is an Integer, a Float or a Symbol, it
656
- # raises a TypeError.
657
- #
658
- # Object.new.singleton_class #=> #<Class:#<Object:0xb7ce1e24>>
659
- # String.singleton_class #=> #<Class:String>
660
- # nil.singleton_class #=> NilClass
661
- #
662
- def `singleton_class`: () -> Class
663
-
664
- # Similar to *method*, searches singleton method only.
665
- #
666
- # class Demo
667
- # def initialize(n)
668
- # @iv = n
669
- # end
670
- # def hello()
671
- # "Hello, @iv = #{@iv}"
672
- # end
673
- # end
674
- #
675
- # k = Demo.new(99)
676
- # def k.hi
677
- # "Hi, @iv = #{@iv}"
678
- # end
679
- # m = k.singleton_method(:hi)
680
- # m.call #=> "Hi, @iv = 99"
681
- # m = k.singleton_method(:hello) #=> NameError
682
- #
683
- def singleton_method: (name name) -> Method
684
-
685
- # Returns an array of the names of singleton methods for *obj*. If the optional
686
- # *all* parameter is true, the list will include methods in modules included in
687
- # *obj*. Only public and protected singleton methods are returned.
688
- #
689
- # module Other
690
- # def three() end
691
- # end
692
- #
693
- # class Single
694
- # def Single.four() end
695
- # end
696
- #
697
- # a = Single.new
698
- #
699
- # def a.one()
700
- # end
701
- #
702
- # class << a
703
- # include Other
704
- # def two()
705
- # end
706
- # end
707
- #
708
- # Single.singleton_methods #=> [:four]
709
- # a.singleton_methods(false) #=> [:two, :one]
710
- # a.singleton_methods #=> [:two, :one, :three]
711
- #
712
- def singleton_methods: () -> Array[Symbol]
713
-
714
- # Mark the object as tainted.
715
- #
716
- # Objects that are marked as tainted will be restricted from various built-in
717
- # methods. This is to prevent insecure data, such as command-line arguments or
718
- # strings read from Kernel#gets, from inadvertently compromising the user's
719
- # system.
720
- #
721
- # To check whether an object is tainted, use #tainted?.
722
- #
723
- # You should only untaint a tainted object if your code has inspected it and
724
- # determined that it is safe. To do so use #untaint.
725
- #
726
- def taint: () -> self
727
-
728
- # Deprecated method that is equivalent to #taint.
729
- #
730
- alias untrust taint
731
-
732
- # Returns true if the object is tainted.
733
- #
734
- # See #taint for more information.
735
- #
736
- def tainted?: () -> bool
737
-
738
- # Deprecated method that is equivalent to #tainted?.
739
- #
740
- alias untrusted? tainted?
741
-
742
- # Yields self to the block, and then returns self. The primary purpose of this
743
- # method is to "tap into" a method chain, in order to perform operations on
744
- # intermediate results within the chain.
745
- #
746
- # (1..10) .tap {|x| puts "original: #{x}" }
747
- # .to_a .tap {|x| puts "array: #{x}" }
748
- # .select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
749
- # .map {|x| x*x } .tap {|x| puts "squares: #{x}" }
750
- #
751
- def tap: () { (self) -> void } -> self
752
-
753
- # Yields self to the block and returns the result of the block.
754
- #
755
- # 3.next.then {|x| x**x }.to_s #=> "256"
756
- # "my string".yield_self {|s| s.upcase } #=> "MY STRING"
757
- #
758
- # Good usage for `yield_self` is value piping in method chains:
759
- #
760
- # require 'open-uri'
761
- # require 'json'
762
- #
763
- # construct_url(arguments).
764
- # yield_self {|url| open(url).read }.
765
- # yield_self {|response| JSON.parse(response) }
766
- #
767
- # When called without block, the method returns `Enumerator`, which can be used,
768
- # for example, for conditional circuit-breaking:
769
- #
770
- # # meets condition, no-op
771
- # 1.yield_self.detect(&:odd?) # => 1
772
- # # does not meet condition, drop value
773
- # 2.yield_self.detect(&:odd?) # => nil
774
- #
775
- def `yield_self`: [X] () { (self) -> X } -> X
776
- | () -> Enumerator[self, untyped]
777
-
778
- # Returns a string representing *obj*. The default `to_s` prints the object's
779
- # class and an encoding of the object id. As a special case, the top-level
780
- # object that is the initial execution context of Ruby programs returns
781
- # ``main''.
782
- #
783
- def to_s: () -> String
784
-
785
- # Removes the tainted mark from the object.
786
- #
787
- # See #taint for more information.
788
- #
789
- def untaint: () -> self
790
-
791
- # Deprecated method that is equivalent to #untaint.
792
- #
793
- alias trust untaint
794
-
795
- # Yields self to the block and returns the result of the block.
796
- #
797
- # 3.next.then {|x| x**x }.to_s #=> "256"
798
- # "my string".yield_self {|s| s.upcase } #=> "MY STRING"
799
- #
800
- # Good usage for `yield_self` is value piping in method chains:
801
- #
802
- # require 'open-uri'
803
- # require 'json'
804
- #
805
- # construct_url(arguments).
806
- # yield_self {|url| open(url).read }.
807
- # yield_self {|response| JSON.parse(response) }
808
- #
809
- # When called without block, the method returns `Enumerator`, which can be used,
810
- # for example, for conditional circuit-breaking:
811
- #
812
- # # meets condition, no-op
813
- # 1.yield_self.detect(&:odd?) # => 1
814
- # # does not meet condition, drop value
815
- # 2.yield_self.detect(&:odd?) # => nil
816
- #
817
- alias then yield_self
818
- end
819
-
820
- interface _Writeable
821
- def write: (untyped) -> void
822
- end
823
-
824
- type Object::name = Symbol | String