rbs 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +28 -0
  3. data/.gitignore +12 -0
  4. data/.rubocop.yml +15 -0
  5. data/BSDL +22 -0
  6. data/CHANGELOG.md +9 -0
  7. data/COPYING +56 -0
  8. data/Gemfile +6 -0
  9. data/README.md +93 -0
  10. data/Rakefile +142 -0
  11. data/bin/annotate-with-rdoc +157 -0
  12. data/bin/console +14 -0
  13. data/bin/query-rdoc +103 -0
  14. data/bin/setup +10 -0
  15. data/bin/sort +89 -0
  16. data/bin/test_runner.rb +16 -0
  17. data/docs/CONTRIBUTING.md +97 -0
  18. data/docs/sigs.md +148 -0
  19. data/docs/stdlib.md +152 -0
  20. data/docs/syntax.md +528 -0
  21. data/exe/rbs +7 -0
  22. data/lib/rbs.rb +64 -0
  23. data/lib/rbs/ast/annotation.rb +27 -0
  24. data/lib/rbs/ast/comment.rb +27 -0
  25. data/lib/rbs/ast/declarations.rb +395 -0
  26. data/lib/rbs/ast/members.rb +362 -0
  27. data/lib/rbs/buffer.rb +50 -0
  28. data/lib/rbs/builtin_names.rb +55 -0
  29. data/lib/rbs/cli.rb +558 -0
  30. data/lib/rbs/constant.rb +26 -0
  31. data/lib/rbs/constant_table.rb +150 -0
  32. data/lib/rbs/definition.rb +170 -0
  33. data/lib/rbs/definition_builder.rb +919 -0
  34. data/lib/rbs/environment.rb +281 -0
  35. data/lib/rbs/environment_loader.rb +136 -0
  36. data/lib/rbs/environment_walker.rb +124 -0
  37. data/lib/rbs/errors.rb +187 -0
  38. data/lib/rbs/location.rb +102 -0
  39. data/lib/rbs/method_type.rb +123 -0
  40. data/lib/rbs/namespace.rb +91 -0
  41. data/lib/rbs/parser.y +1344 -0
  42. data/lib/rbs/prototype/rb.rb +553 -0
  43. data/lib/rbs/prototype/rbi.rb +587 -0
  44. data/lib/rbs/prototype/runtime.rb +381 -0
  45. data/lib/rbs/substitution.rb +46 -0
  46. data/lib/rbs/test.rb +26 -0
  47. data/lib/rbs/test/errors.rb +61 -0
  48. data/lib/rbs/test/hook.rb +294 -0
  49. data/lib/rbs/test/setup.rb +58 -0
  50. data/lib/rbs/test/spy.rb +325 -0
  51. data/lib/rbs/test/test_helper.rb +183 -0
  52. data/lib/rbs/test/type_check.rb +254 -0
  53. data/lib/rbs/type_name.rb +70 -0
  54. data/lib/rbs/types.rb +936 -0
  55. data/lib/rbs/variance_calculator.rb +138 -0
  56. data/lib/rbs/vendorer.rb +47 -0
  57. data/lib/rbs/version.rb +3 -0
  58. data/lib/rbs/writer.rb +269 -0
  59. data/lib/ruby/signature.rb +7 -0
  60. data/rbs.gemspec +46 -0
  61. data/stdlib/abbrev/abbrev.rbs +60 -0
  62. data/stdlib/base64/base64.rbs +71 -0
  63. data/stdlib/benchmark/benchmark.rbs +372 -0
  64. data/stdlib/builtin/array.rbs +1997 -0
  65. data/stdlib/builtin/basic_object.rbs +280 -0
  66. data/stdlib/builtin/binding.rbs +177 -0
  67. data/stdlib/builtin/builtin.rbs +45 -0
  68. data/stdlib/builtin/class.rbs +145 -0
  69. data/stdlib/builtin/comparable.rbs +116 -0
  70. data/stdlib/builtin/complex.rbs +400 -0
  71. data/stdlib/builtin/constants.rbs +37 -0
  72. data/stdlib/builtin/data.rbs +5 -0
  73. data/stdlib/builtin/deprecated.rbs +2 -0
  74. data/stdlib/builtin/dir.rbs +413 -0
  75. data/stdlib/builtin/encoding.rbs +607 -0
  76. data/stdlib/builtin/enumerable.rbs +404 -0
  77. data/stdlib/builtin/enumerator.rbs +260 -0
  78. data/stdlib/builtin/errno.rbs +781 -0
  79. data/stdlib/builtin/errors.rbs +582 -0
  80. data/stdlib/builtin/exception.rbs +194 -0
  81. data/stdlib/builtin/false_class.rbs +40 -0
  82. data/stdlib/builtin/fiber.rbs +68 -0
  83. data/stdlib/builtin/fiber_error.rbs +12 -0
  84. data/stdlib/builtin/file.rbs +1076 -0
  85. data/stdlib/builtin/file_test.rbs +59 -0
  86. data/stdlib/builtin/float.rbs +696 -0
  87. data/stdlib/builtin/gc.rbs +243 -0
  88. data/stdlib/builtin/hash.rbs +1029 -0
  89. data/stdlib/builtin/integer.rbs +707 -0
  90. data/stdlib/builtin/io.rbs +683 -0
  91. data/stdlib/builtin/kernel.rbs +576 -0
  92. data/stdlib/builtin/marshal.rbs +161 -0
  93. data/stdlib/builtin/match_data.rbs +271 -0
  94. data/stdlib/builtin/math.rbs +369 -0
  95. data/stdlib/builtin/method.rbs +185 -0
  96. data/stdlib/builtin/module.rbs +1104 -0
  97. data/stdlib/builtin/nil_class.rbs +82 -0
  98. data/stdlib/builtin/numeric.rbs +409 -0
  99. data/stdlib/builtin/object.rbs +824 -0
  100. data/stdlib/builtin/proc.rbs +429 -0
  101. data/stdlib/builtin/process.rbs +1227 -0
  102. data/stdlib/builtin/random.rbs +267 -0
  103. data/stdlib/builtin/range.rbs +226 -0
  104. data/stdlib/builtin/rational.rbs +424 -0
  105. data/stdlib/builtin/rb_config.rbs +57 -0
  106. data/stdlib/builtin/regexp.rbs +1083 -0
  107. data/stdlib/builtin/ruby_vm.rbs +14 -0
  108. data/stdlib/builtin/signal.rbs +55 -0
  109. data/stdlib/builtin/string.rbs +1901 -0
  110. data/stdlib/builtin/string_io.rbs +284 -0
  111. data/stdlib/builtin/struct.rbs +40 -0
  112. data/stdlib/builtin/symbol.rbs +228 -0
  113. data/stdlib/builtin/thread.rbs +1108 -0
  114. data/stdlib/builtin/thread_group.rbs +23 -0
  115. data/stdlib/builtin/time.rbs +1047 -0
  116. data/stdlib/builtin/trace_point.rbs +290 -0
  117. data/stdlib/builtin/true_class.rbs +46 -0
  118. data/stdlib/builtin/unbound_method.rbs +153 -0
  119. data/stdlib/builtin/warning.rbs +17 -0
  120. data/stdlib/coverage/coverage.rbs +62 -0
  121. data/stdlib/csv/csv.rbs +773 -0
  122. data/stdlib/erb/erb.rbs +392 -0
  123. data/stdlib/find/find.rbs +40 -0
  124. data/stdlib/ipaddr/ipaddr.rbs +247 -0
  125. data/stdlib/json/json.rbs +335 -0
  126. data/stdlib/pathname/pathname.rbs +1093 -0
  127. data/stdlib/prime/integer-extension.rbs +23 -0
  128. data/stdlib/prime/prime.rbs +188 -0
  129. data/stdlib/securerandom/securerandom.rbs +9 -0
  130. data/stdlib/set/set.rbs +301 -0
  131. data/stdlib/tmpdir/tmpdir.rbs +53 -0
  132. metadata +292 -0
@@ -0,0 +1,824 @@
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