rbs 1.0.0 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +10 -4
  3. data/CHANGELOG.md +47 -0
  4. data/Gemfile +6 -2
  5. data/README.md +1 -1
  6. data/Rakefile +3 -4
  7. data/bin/test_runner.rb +4 -5
  8. data/core/array.rbs +2 -2
  9. data/core/complex.rbs +1 -1
  10. data/core/encoding.rbs +1 -1
  11. data/core/enumerable.rbs +15 -1
  12. data/core/file.rbs +3 -1
  13. data/core/integer.rbs +2 -1
  14. data/core/io.rbs +75 -4
  15. data/core/kernel.rbs +56 -56
  16. data/core/module.rbs +3 -3
  17. data/core/rational.rbs +2 -1
  18. data/core/string.rbs +2 -1
  19. data/core/symbol.rbs +2 -1
  20. data/core/time.rbs +2 -1
  21. data/core/unbound_method.rbs +16 -0
  22. data/docs/CONTRIBUTING.md +2 -2
  23. data/docs/stdlib.md +50 -12
  24. data/goodcheck.yml +1 -1
  25. data/lib/rbs/ast/members.rb +13 -0
  26. data/lib/rbs/definition_builder.rb +36 -25
  27. data/lib/rbs/definition_builder/method_builder.rb +9 -2
  28. data/lib/rbs/errors.rb +3 -0
  29. data/lib/rbs/parser.rb +347 -333
  30. data/lib/rbs/parser.y +12 -2
  31. data/lib/rbs/prototype/rb.rb +14 -4
  32. data/lib/rbs/test/setup_helper.rb +0 -1
  33. data/lib/rbs/version.rb +1 -1
  34. data/rbs.gemspec +1 -0
  35. data/sig/definition_builder.rbs +3 -2
  36. data/sig/members.rbs +2 -0
  37. data/stdlib/bigdecimal/0/big_decimal.rbs +1 -1
  38. data/stdlib/date/0/date.rbs +1 -1
  39. data/stdlib/fileutils/0/fileutils.rbs +585 -0
  40. data/stdlib/json/0/json.rbs +64 -0
  41. data/stdlib/pathname/0/pathname.rbs +3 -2
  42. data/stdlib/prettyprint/0/prettyprint.rbs +366 -0
  43. data/stdlib/set/0/set.rbs +7 -0
  44. data/stdlib/timeout/0/timeout.rbs +57 -0
  45. data/stdlib/uri/0/common.rbs +1 -1
  46. data/stdlib/uri/0/rfc2396_parser.rbs +144 -7
  47. data/steep/Gemfile.lock +17 -19
  48. metadata +7 -5
  49. data/core/data.rbs +0 -5
@@ -339,3 +339,67 @@ JSON::VERSION_BUILD: Integer
339
339
  JSON::VERSION_MAJOR: Integer
340
340
 
341
341
  JSON::VERSION_MINOR: Integer
342
+
343
+ class Object
344
+ # Converts this object to a string (calling #to_s), converts
345
+ # it to a JSON string, and returns the result. This is a fallback, if no
346
+ # special method #to_json was defined for some object.
347
+ #
348
+ def to_json: (?JSON::State state) -> String
349
+ end
350
+
351
+ class NilClass
352
+ # Returns a JSON string for nil: 'null'.
353
+ #
354
+ def to_json: (?JSON::State state) -> String
355
+ end
356
+
357
+ class TrueClass
358
+ # Returns a JSON string for true: 'true'.
359
+ #
360
+ def to_json: (?JSON::State state) -> String
361
+ end
362
+
363
+ class FalseClass
364
+ # Returns a JSON string for false: 'false'.
365
+ #
366
+ def to_json: (?JSON::State state) -> String
367
+ end
368
+
369
+ class String
370
+ # This string should be encoded with UTF-8 A call to this method
371
+ # returns a JSON string encoded with UTF16 big endian characters as
372
+ # \u????.
373
+ #
374
+ def to_json: (?JSON::State state) -> String
375
+ end
376
+
377
+ class Integer
378
+ # Returns a JSON string representation for this Integer number.
379
+ #
380
+ def to_json: (?JSON::State state) -> String
381
+ end
382
+
383
+ class Float
384
+ # Returns a JSON string representation for this Float number.
385
+ #
386
+ def to_json: (?JSON::State state) -> String
387
+ end
388
+
389
+ class Hash[unchecked out K, unchecked out V]
390
+ # Returns a JSON string containing a JSON object, that is generated from
391
+ # this Hash instance.
392
+ # _state_ is a JSON::State object, that can also be used to configure the
393
+ # produced JSON string output further.
394
+ #
395
+ def to_json: (?JSON::State state) -> String
396
+ end
397
+
398
+ class Array[unchecked out Elem]
399
+ # Returns a JSON string containing a JSON array, that is generated from
400
+ # this Array instance.
401
+ # _state_ is a JSON::State object, that can also be used to configure the
402
+ # produced JSON string output further.
403
+ #
404
+ def to_json: (?JSON::State state) -> String
405
+ end
@@ -240,7 +240,8 @@ class Pathname
240
240
  # relative to the right argument. Or it will return `nil` if the arguments are
241
241
  # not comparable.
242
242
  #
243
- def <=>: (untyped other) -> Integer?
243
+ def <=>: (Pathname other) -> Integer
244
+ | (untyped other) -> nil
244
245
 
245
246
  # Compare this pathname with `other`. The comparison is string-based. Be aware
246
247
  # that two different paths (`foo.txt` and `./foo.txt`) can refer to the same
@@ -1091,5 +1092,5 @@ module Kernel
1091
1092
  #
1092
1093
  # See also Pathname::new for more information.
1093
1094
  #
1094
- def Pathname: (String | Pathname) -> Pathname
1095
+ def self?.Pathname: (String | Pathname) -> Pathname
1095
1096
  end
@@ -0,0 +1,366 @@
1
+ # This class implements a pretty printing algorithm. It finds line breaks and
2
+ # nice indentations for grouped structure.
3
+ #
4
+ # By default, the class assumes that primitive elements are strings and each
5
+ # byte in the strings have single column in width. But it can be used for other
6
+ # situations by giving suitable arguments for some methods:
7
+ # * newline object and space generation block for PrettyPrint.new
8
+ # * optional width argument for PrettyPrint#text
9
+ # * PrettyPrint#breakable
10
+ #
11
+ #
12
+ # There are several candidate uses:
13
+ # * text formatting using proportional fonts
14
+ # * multibyte characters which has columns different to number of bytes
15
+ # * non-string formatting
16
+ #
17
+ #
18
+ # ## Bugs
19
+ # * Box based formatting?
20
+ # * Other (better) model/algorithm?
21
+ #
22
+ #
23
+ # Report any bugs at http://bugs.ruby-lang.org
24
+ #
25
+ # ## References
26
+ # Christian Lindig, Strictly Pretty, March 2000,
27
+ # http://www.st.cs.uni-sb.de/~lindig/papers/#pretty
28
+ #
29
+ # Philip Wadler, A prettier printer, March 1998,
30
+ # http://homepages.inf.ed.ac.uk/wadler/topics/language-design.html#prettier
31
+ #
32
+ # ## Author
33
+ # Tanaka Akira <akr@fsij.org>
34
+ class PrettyPrint
35
+ interface _Output
36
+ def <<: (String) -> void
37
+ end
38
+
39
+ # This is a convenience method which is same as follows:
40
+ #
41
+ # begin
42
+ # q = PrettyPrint.new(output, maxwidth, newline, &genspace)
43
+ # ...
44
+ # q.flush
45
+ # output
46
+ # end
47
+ #
48
+ def self.format: (?untyped output, ?Integer maxwidth, ?String newline, ?^(Integer) -> Integer genspace) { (PrettyPrint) -> untyped } -> _Output
49
+
50
+ # This is similar to PrettyPrint::format but the result has no breaks.
51
+ #
52
+ # `maxwidth`, `newline` and `genspace` are ignored.
53
+ #
54
+ # The invocation of `breakable` in the block doesn't break a line and is treated
55
+ # as just an invocation of `text`.
56
+ #
57
+ def self.singleline_format: (?untyped output, ?Integer? maxwidth, ?String? newline, ?^(Integer) -> Integer? genspace ) { (PrettyPrint::SingleLine) -> untyped } -> _Output
58
+
59
+ # Creates a buffer for pretty printing.
60
+ #
61
+ # `output` is an output target. If it is not specified, '' is assumed. It should
62
+ # have a << method which accepts the first argument `obj` of PrettyPrint#text,
63
+ # the first argument `sep` of PrettyPrint#breakable, the first argument
64
+ # `newline` of PrettyPrint.new, and the result of a given block for
65
+ # PrettyPrint.new.
66
+ #
67
+ # `maxwidth` specifies maximum line length. If it is not specified, 79 is
68
+ # assumed. However actual outputs may overflow `maxwidth` if long non-breakable
69
+ # texts are provided.
70
+ #
71
+ # `newline` is used for line breaks. "n" is used if it is not specified.
72
+ #
73
+ # The block is used to generate spaces. {|width| ' ' * width} is used if it is
74
+ # not given.
75
+ #
76
+ def initialize: (?untyped output, ?Integer maxwidth, ?String newline, ?^(Integer) -> Integer genspace) -> void
77
+
78
+ # The output object.
79
+ #
80
+ # This defaults to '', and should accept the << method
81
+ attr_reader output: _Output
82
+
83
+ # The maximum width of a line, before it is separated in to a newline
84
+ #
85
+ # This defaults to 79, and should be a Fixnum
86
+ attr_reader maxwidth: Integer
87
+
88
+ # The value that is appended to +output+ to add a new line.
89
+ #
90
+ # This defaults to "\n", and should be String
91
+ attr_reader newline: String
92
+
93
+ # A lambda or Proc, that takes one argument, of a Fixnum, and returns
94
+ # the corresponding number of spaces.
95
+ #
96
+ # By default this is:
97
+ # lambda {|n| ' ' * n}
98
+ attr_reader genspace: Proc
99
+
100
+ # The number of spaces to be indented
101
+ attr_reader indent: Integer
102
+
103
+ # The PrettyPrint::GroupQueue of groups in stack to be pretty printed
104
+ attr_reader group_queue: PrettyPrint::GroupQueue
105
+
106
+ # Returns the group most recently added to the stack.
107
+ #
108
+ # Contrived example:
109
+ # out = ""
110
+ # => ""
111
+ # q = PrettyPrint.new(out)
112
+ # => #<PrettyPrint:0x82f85c0 @output="", @maxwidth=79, @newline="\n", @genspace=#<Proc:0x82f8368@/home/vbatts/.rvm/rubies/ruby-head/lib/ruby/2.0.0/prettyprint.rb:82 (lambda)>, @output_width=0, @buffer_width=0, @buffer=[], @group_stack=[#<PrettyPrint::Group:0x82f8138 @depth=0, @breakables=[], @break=false>], @group_queue=#<PrettyPrint::GroupQueue:0x82fb7c0 @queue=[[#<PrettyPrint::Group:0x82f8138 @depth=0, @breakables=[], @break=false>]]>, @indent=0>
113
+ # q.group {
114
+ # q.text q.current_group.inspect
115
+ # q.text q.newline
116
+ # q.group(q.current_group.depth + 1) {
117
+ # q.text q.current_group.inspect
118
+ # q.text q.newline
119
+ # q.group(q.current_group.depth + 1) {
120
+ # q.text q.current_group.inspect
121
+ # q.text q.newline
122
+ # q.group(q.current_group.depth + 1) {
123
+ # q.text q.current_group.inspect
124
+ # q.text q.newline
125
+ # }
126
+ # }
127
+ # }
128
+ # }
129
+ # => 284
130
+ # puts out
131
+ # #<PrettyPrint::Group:0x8354758 @depth=1, @breakables=[], @break=false>
132
+ # #<PrettyPrint::Group:0x8354550 @depth=2, @breakables=[], @break=false>
133
+ # #<PrettyPrint::Group:0x83541cc @depth=3, @breakables=[], @break=false>
134
+ # #<PrettyPrint::Group:0x8347e54 @depth=4, @breakables=[], @break=false>
135
+ #
136
+ def current_group: () -> PrettyPrint::Group
137
+
138
+ # Breaks the buffer into lines that are shorter than #maxwidth
139
+ #
140
+ def break_outmost_groups: () -> untyped
141
+
142
+ # This adds `obj` as a text of `width` columns in width.
143
+ #
144
+ # If `width` is not specified, obj.length is used.
145
+ #
146
+ def text: (String obj, ?Integer width) -> void
147
+
148
+ # This is similar to #breakable except the decision to break or not is
149
+ # determined individually.
150
+ #
151
+ # Two #fill_breakable under a group may cause 4 results: (break,break),
152
+ # (break,non-break), (non-break,break), (non-break,non-break). This is different
153
+ # to #breakable because two #breakable under a group may cause 2 results:
154
+ # (break,break), (non-break,non-break).
155
+ #
156
+ # The text `sep` is inserted if a line is not broken at this point.
157
+ #
158
+ # If `sep` is not specified, " " is used.
159
+ #
160
+ # If `width` is not specified, `sep.length` is used. You will have to specify
161
+ # this when `sep` is a multibyte character, for example.
162
+ #
163
+ def fill_breakable: (?String sep, ?Integer width) -> void
164
+
165
+ # This says "you can break a line here if necessary", and a `width`-column text
166
+ # `sep` is inserted if a line is not broken at the point.
167
+ #
168
+ # If `sep` is not specified, " " is used.
169
+ #
170
+ # If `width` is not specified, `sep.length` is used. You will have to specify
171
+ # this when `sep` is a multibyte character, for example.
172
+ #
173
+ def breakable: (?String sep, ?Integer width) -> void
174
+
175
+ # Groups line break hints added in the block. The line break hints are all to be
176
+ # used or not.
177
+ #
178
+ # If `indent` is specified, the method call is regarded as nested by
179
+ # nest(indent) { ... }.
180
+ #
181
+ # If `open_obj` is specified, `text open_obj, open_width` is called before
182
+ # grouping. If `close_obj` is specified, `text close_obj, close_width` is called
183
+ # after grouping.
184
+ #
185
+ def group: (?::Integer indent, ?::String open_obj, ?::String close_obj, ?Integer open_width, ?Integer close_width) { () -> untyped } -> Integer
186
+
187
+ # Takes a block and queues a new group that is indented 1 level further.
188
+ #
189
+ def group_sub: () { () -> untyped } -> untyped
190
+
191
+ # Increases left margin after newline with `indent` for line breaks added in the
192
+ # block.
193
+ #
194
+ def nest: (Integer indent) { () -> untyped } -> void
195
+
196
+ # outputs buffered data.
197
+ #
198
+ def flush: () -> Integer
199
+
200
+ class Text
201
+ # Creates a new text object.
202
+ #
203
+ # This constructor takes no arguments.
204
+ #
205
+ # The workflow is to append a PrettyPrint::Text object to the buffer, and
206
+ # being able to call the buffer.last() to reference it.
207
+ #
208
+ # As there are objects, use PrettyPrint::Text#add to include the objects
209
+ # and the width to utilized by the String version of this object.
210
+ def initialize: () -> void
211
+
212
+ # The total width of the objects included in this Text object.
213
+ attr_reader width: Integer
214
+
215
+ # Render the String text of the objects that have been added to this Text object.
216
+ #
217
+ # Output the text to +out+, and increment the width to +output_width+
218
+ def output: (untyped `out`, untyped output_width) -> untyped
219
+
220
+ # Include +obj+ in the objects to be pretty printed, and increment
221
+ # this Text object's total width by +width+
222
+ def add: (untyped obj, Integer width) -> void
223
+ end
224
+
225
+ class Breakable
226
+ # Create a new Breakable object.
227
+ #
228
+ # Arguments:
229
+ # * +sep+ String of the separator
230
+ # * +width+ Fixnum width of the +sep+
231
+ # * +q+ parent PrettyPrint object, to base from
232
+ def initialize: (String sep, Integer width, PrettyPrint q) -> void
233
+
234
+ # Holds the separator String
235
+ #
236
+ # The +sep+ argument from ::new
237
+ attr_reader obj: String
238
+
239
+ # The width of +obj+ / +sep+
240
+ attr_reader width: Integer
241
+
242
+ # The number of spaces to indent.
243
+ #
244
+ # This is inferred from +q+ within PrettyPrint, passed in ::new
245
+ attr_reader indent: Integer
246
+
247
+ # Render the String text of the objects that have been added to this
248
+ # Breakable object.
249
+ #
250
+ # Output the text to +out+, and increment the width to +output_width+
251
+ def output: (untyped `out`, Integer output_width) -> untyped
252
+ end
253
+
254
+ class Group
255
+ # The Group class is used for making indentation easier.
256
+ #
257
+ # While this class does neither the breaking into newlines nor indentation,
258
+ # it is used in a stack (as well as a queue) within PrettyPrint, to group
259
+ # objects.
260
+ #
261
+ # For information on using groups, see PrettyPrint#group
262
+ #
263
+ # This class is intended for internal use of the PrettyPrint buffers.
264
+ # :nodoc:
265
+ # Create a Group object
266
+ #
267
+ # Arguments:
268
+ # * +depth+ - this group's relation to previous groups
269
+ def initialize: (untyped depth) -> void
270
+
271
+ # This group's relation to previous groups
272
+ attr_reader depth: untyped
273
+
274
+ # Array to hold the Breakable objects for this Group
275
+ attr_reader breakables: Array[PrettyPrint::Breakable]
276
+
277
+ # Makes a break for this Group, and returns true
278
+ def break: () -> bool
279
+
280
+ # Boolean of whether this Group has made a break
281
+ def break?: () -> bool
282
+
283
+ # Boolean of whether this Group has been queried for being first
284
+ #
285
+ # This is used as a predicate, and ought to be called first.
286
+ def first?: () -> bool
287
+ end
288
+
289
+ class GroupQueue
290
+ # The GroupQueue class is used for managing the queue of Group to be pretty
291
+ # printed.
292
+ #
293
+ # This queue groups the Group objects, based on their depth.
294
+ #
295
+ # This class is intended for internal use of the PrettyPrint buffers.
296
+ # :nodoc:
297
+ # Create a GroupQueue object
298
+ #
299
+ # Arguments:
300
+ # * +groups+ - one or more PrettyPrint::Group objects
301
+ def initialize: (*untyped groups) -> void
302
+
303
+ # Enqueue +group+
304
+ #
305
+ # This does not strictly append the group to the end of the queue,
306
+ # but instead adds it in line, base on the +group.depth+
307
+ def enq: (untyped group) -> void
308
+
309
+ # Returns the outer group of the queue
310
+ def deq: () -> (PrettyPrint::Group | nil)
311
+
312
+ # Remote +group+ from this queue
313
+ def delete: (PrettyPrint::Group group) -> void
314
+ end
315
+
316
+ # PrettyPrint::SingleLine is used by PrettyPrint.singleline_format
317
+ #
318
+ # It is passed to be similar to a PrettyPrint object itself, by responding to:
319
+ # * #text
320
+ # * #breakable
321
+ # * #nest
322
+ # * #group
323
+ # * #flush
324
+ # * #first?
325
+ #
326
+ # but instead, the output has no line breaks
327
+ #
328
+ class SingleLine
329
+ # Create a PrettyPrint::SingleLine object
330
+ #
331
+ # Arguments:
332
+ # * +output+ - String (or similar) to store rendered text. Needs to respond to '<<'
333
+ # * +maxwidth+ - Argument position expected to be here for compatibility.
334
+ # This argument is a noop.
335
+ # * +newline+ - Argument position expected to be here for compatibility.
336
+ # This argument is a noop.
337
+ def initialize: (String | untyped output, ?Integer? maxwidth, ?String? newline) -> void
338
+
339
+ # Add +obj+ to the text to be output.
340
+ #
341
+ # +width+ argument is here for compatibility. It is a noop argument.
342
+ def text: (String obj, ?Integer? width) -> void
343
+
344
+ # Appends +sep+ to the text to be output. By default +sep+ is ' '
345
+ #
346
+ # +width+ argument is here for compatibility. It is a noop argument.
347
+ def breakable: (?String sep, ?Integer? width) -> void
348
+
349
+ def nest: (untyped indent) { () -> untyped } -> void
350
+
351
+ # Opens a block for grouping objects to be pretty printed.
352
+ #
353
+ # Arguments:
354
+ # * +indent+ - noop argument. Present for compatibility.
355
+ # * +open_obj+ - text appended before the &blok. Default is ''
356
+ # * +close_obj+ - text appended after the &blok. Default is ''
357
+ # * +open_width+ - noop argument. Present for compatibility.
358
+ # * +close_width+ - noop argument. Present for compatibility.
359
+ def group: (?Integer? indent, ?String open_obj, ?String close_obj, ?Integer? open_width, ?Integer? close_width) { () -> untyped } -> untyped
360
+
361
+ def flush: () -> nil
362
+
363
+ # This is used as a predicate, and ought to be called first.
364
+ def first?: () -> bool
365
+ end
366
+ end