rbs 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -0
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +6 -1
  5. data/core/array.rbs +2866 -1086
  6. data/core/basic_object.rbs +150 -30
  7. data/core/binding.rbs +33 -0
  8. data/core/builtin.rbs +4 -4
  9. data/core/class.rbs +43 -5
  10. data/core/comparable.rbs +57 -0
  11. data/core/complex.rbs +170 -4
  12. data/core/constants.rbs +51 -0
  13. data/core/deprecated.rbs +7 -0
  14. data/core/dir.rbs +305 -20
  15. data/core/encoding.rbs +472 -77
  16. data/core/enumerable.rbs +2173 -234
  17. data/core/enumerator.rbs +448 -182
  18. data/core/env.rbs +448 -1
  19. data/core/errno.rbs +1 -10
  20. data/core/errors.rbs +152 -2
  21. data/core/exception.rbs +201 -127
  22. data/core/false_class.rbs +27 -0
  23. data/core/fiber.rbs +118 -37
  24. data/core/fiber_error.rbs +8 -9
  25. data/core/file.rbs +1059 -139
  26. data/core/file_test.rbs +287 -32
  27. data/core/float.rbs +776 -300
  28. data/core/gc.rbs +185 -34
  29. data/core/global_variables.rbs +5 -1
  30. data/core/hash.rbs +1582 -649
  31. data/core/integer.rbs +974 -204
  32. data/core/io/buffer.rbs +710 -0
  33. data/core/io/wait.rbs +29 -8
  34. data/core/io.rbs +2438 -417
  35. data/core/kernel.rbs +2315 -316
  36. data/core/marshal.rbs +37 -2
  37. data/core/match_data.rbs +123 -6
  38. data/core/math.rbs +126 -6
  39. data/core/method.rbs +226 -102
  40. data/core/module.rbs +421 -45
  41. data/core/nil_class.rbs +64 -0
  42. data/core/numeric.rbs +620 -142
  43. data/core/object.rbs +453 -81
  44. data/core/object_space.rbs +92 -2
  45. data/core/proc.rbs +482 -285
  46. data/core/process.rbs +443 -34
  47. data/core/ractor.rbs +232 -9
  48. data/core/random.rbs +151 -52
  49. data/core/range.rbs +885 -160
  50. data/core/rational.rbs +122 -6
  51. data/core/rb_config.rbs +14 -4
  52. data/core/refinement.rbs +44 -0
  53. data/core/regexp.rbs +156 -14
  54. data/core/ruby_vm.rbs +42 -3
  55. data/core/signal.rbs +78 -39
  56. data/core/string.rbs +2123 -567
  57. data/core/string_io.rbs +204 -0
  58. data/core/struct.rbs +283 -28
  59. data/core/symbol.rbs +304 -30
  60. data/core/thread.rbs +1288 -688
  61. data/core/thread_group.rbs +66 -10
  62. data/core/time.rbs +643 -217
  63. data/core/trace_point.rbs +100 -12
  64. data/core/true_class.rbs +24 -0
  65. data/core/unbound_method.rbs +73 -7
  66. data/core/warning.rbs +37 -12
  67. data/docs/CONTRIBUTING.md +40 -34
  68. data/docs/stdlib.md +3 -102
  69. data/lib/rbs/annotate/annotations.rb +197 -0
  70. data/lib/rbs/annotate/formatter.rb +80 -0
  71. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  72. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  73. data/lib/rbs/annotate.rb +6 -0
  74. data/lib/rbs/cli.rb +45 -1
  75. data/lib/rbs/definition_builder.rb +5 -1
  76. data/lib/rbs/location_aux.rb +12 -0
  77. data/lib/rbs/prototype/rb.rb +12 -0
  78. data/lib/rbs/version.rb +1 -1
  79. data/sig/annotate/annotations.rbs +102 -0
  80. data/sig/annotate/formatter.rbs +24 -0
  81. data/sig/annotate/rdoc_annotater.rbs +82 -0
  82. data/sig/annotate/rdoc_source.rbs +30 -0
  83. data/sig/cli.rbs +2 -0
  84. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  85. data/sig/location.rbs +6 -0
  86. data/sig/method_types.rbs +5 -1
  87. data/sig/polyfill.rbs +78 -0
  88. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  89. data/stdlib/abbrev/0/array.rbs +26 -0
  90. data/stdlib/base64/0/base64.rbs +31 -0
  91. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  92. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  93. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  94. data/stdlib/cgi/0/core.rbs +59 -0
  95. data/stdlib/coverage/0/coverage.rbs +164 -2
  96. data/stdlib/csv/0/csv.rbs +2862 -398
  97. data/stdlib/date/0/date.rbs +483 -25
  98. data/stdlib/date/0/date_time.rbs +187 -12
  99. data/stdlib/dbm/0/dbm.rbs +152 -17
  100. data/stdlib/digest/0/digest.rbs +146 -0
  101. data/stdlib/erb/0/erb.rbs +65 -245
  102. data/stdlib/fiber/0/fiber.rbs +73 -91
  103. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  104. data/stdlib/find/0/find.rbs +9 -0
  105. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  106. data/stdlib/io-console/0/io-console.rbs +227 -15
  107. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  108. data/stdlib/json/0/json.rbs +1146 -144
  109. data/stdlib/logger/0/formatter.rbs +24 -0
  110. data/stdlib/logger/0/log_device.rbs +64 -0
  111. data/stdlib/logger/0/logger.rbs +165 -13
  112. data/stdlib/logger/0/period.rbs +10 -0
  113. data/stdlib/logger/0/severity.rbs +26 -0
  114. data/stdlib/monitor/0/monitor.rbs +163 -0
  115. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  116. data/stdlib/net-http/0/net-http.rbs +1492 -683
  117. data/stdlib/nkf/0/nkf.rbs +372 -0
  118. data/stdlib/objspace/0/objspace.rbs +149 -90
  119. data/stdlib/openssl/0/openssl.rbs +8108 -71
  120. data/stdlib/optparse/0/optparse.rbs +487 -19
  121. data/stdlib/pathname/0/pathname.rbs +425 -124
  122. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  123. data/stdlib/prime/0/integer-extension.rbs +20 -2
  124. data/stdlib/prime/0/prime.rbs +88 -21
  125. data/stdlib/pstore/0/pstore.rbs +102 -0
  126. data/stdlib/pty/0/pty.rbs +64 -14
  127. data/stdlib/resolv/0/resolv.rbs +420 -31
  128. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  129. data/stdlib/rubygems/0/config_file.rbs +33 -1
  130. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  131. data/stdlib/rubygems/0/installer.rbs +13 -1
  132. data/stdlib/rubygems/0/path_support.rbs +4 -1
  133. data/stdlib/rubygems/0/platform.rbs +5 -1
  134. data/stdlib/rubygems/0/request_set.rbs +44 -2
  135. data/stdlib/rubygems/0/requirement.rbs +65 -2
  136. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  137. data/stdlib/rubygems/0/source_list.rbs +13 -0
  138. data/stdlib/rubygems/0/specification.rbs +21 -1
  139. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  140. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  141. data/stdlib/rubygems/0/version.rbs +60 -157
  142. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  143. data/stdlib/set/0/set.rbs +420 -106
  144. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  145. data/stdlib/singleton/0/singleton.rbs +20 -0
  146. data/stdlib/socket/0/addrinfo.rbs +210 -9
  147. data/stdlib/socket/0/basic_socket.rbs +103 -11
  148. data/stdlib/socket/0/ip_socket.rbs +31 -9
  149. data/stdlib/socket/0/socket.rbs +586 -38
  150. data/stdlib/socket/0/tcp_server.rbs +22 -2
  151. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  152. data/stdlib/socket/0/udp_socket.rbs +25 -2
  153. data/stdlib/socket/0/unix_server.rbs +22 -2
  154. data/stdlib/socket/0/unix_socket.rbs +45 -5
  155. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  156. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  157. data/stdlib/time/0/time.rbs +208 -116
  158. data/stdlib/timeout/0/timeout.rbs +10 -0
  159. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  160. data/stdlib/tsort/0/cyclic.rbs +1 -0
  161. data/stdlib/tsort/0/interfaces.rbs +1 -0
  162. data/stdlib/tsort/0/tsort.rbs +42 -0
  163. data/stdlib/uri/0/common.rbs +57 -8
  164. data/stdlib/uri/0/file.rbs +55 -109
  165. data/stdlib/uri/0/ftp.rbs +6 -3
  166. data/stdlib/uri/0/generic.rbs +556 -327
  167. data/stdlib/uri/0/http.rbs +26 -115
  168. data/stdlib/uri/0/https.rbs +8 -102
  169. data/stdlib/uri/0/ldap.rbs +143 -137
  170. data/stdlib/uri/0/ldaps.rbs +8 -102
  171. data/stdlib/uri/0/mailto.rbs +3 -0
  172. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  173. data/stdlib/uri/0/ws.rbs +6 -3
  174. data/stdlib/uri/0/wss.rbs +5 -3
  175. data/stdlib/yaml/0/dbm.rbs +151 -87
  176. data/stdlib/yaml/0/store.rbs +6 -0
  177. data/stdlib/zlib/0/zlib.rbs +90 -31
  178. metadata +17 -5
  179. data/lib/rbs/location.rb +0 -221
@@ -1,3 +1,4 @@
1
+ # <!-- rdoc-file=lib/prettyprint.rb -->
1
2
  # This class implements a pretty printing algorithm. It finds line breaks and
2
3
  # nice indentations for grouped structure.
3
4
  #
@@ -31,11 +32,16 @@
31
32
  #
32
33
  # ## Author
33
34
  # Tanaka Akira <akr@fsij.org>
35
+ #
34
36
  class PrettyPrint
35
37
  interface _Output
36
38
  def <<: (String) -> void
37
39
  end
38
40
 
41
+ # <!--
42
+ # rdoc-file=lib/prettyprint.rb
43
+ # - format(output=''.dup, maxwidth=79, newline="\n", genspace=lambda {|n| ' ' * n}) { |q| ... }
44
+ # -->
39
45
  # This is a convenience method which is same as follows:
40
46
  #
41
47
  # begin
@@ -47,6 +53,10 @@ class PrettyPrint
47
53
  #
48
54
  def self.format: (?untyped output, ?Integer maxwidth, ?String newline, ?^(Integer) -> Integer genspace) { (PrettyPrint) -> untyped } -> _Output
49
55
 
56
+ # <!--
57
+ # rdoc-file=lib/prettyprint.rb
58
+ # - singleline_format(output=''.dup, maxwidth=nil, newline=nil, genspace=nil) { |q| ... }
59
+ # -->
50
60
  # This is similar to PrettyPrint::format but the result has no breaks.
51
61
  #
52
62
  # `maxwidth`, `newline` and `genspace` are ignored.
@@ -54,8 +64,12 @@ class PrettyPrint
54
64
  # The invocation of `breakable` in the block doesn't break a line and is treated
55
65
  # as just an invocation of `text`.
56
66
  #
57
- def self.singleline_format: (?untyped output, ?Integer? maxwidth, ?String? newline, ?^(Integer) -> Integer? genspace ) { (PrettyPrint::SingleLine) -> untyped } -> _Output
67
+ def self.singleline_format: (?untyped output, ?Integer? maxwidth, ?String? newline, ?^(Integer) -> Integer? genspace) { (PrettyPrint::SingleLine) -> untyped } -> _Output
58
68
 
69
+ # <!--
70
+ # rdoc-file=lib/prettyprint.rb
71
+ # - new(output=''.dup, maxwidth=79, newline="\n", &genspace)
72
+ # -->
59
73
  # Creates a buffer for pretty printing.
60
74
  #
61
75
  # `output` is an output target. If it is not specified, '' is assumed. It should
@@ -73,36 +87,52 @@ class PrettyPrint
73
87
  # The block is used to generate spaces. {|width| ' ' * width} is used if it is
74
88
  # not given.
75
89
  #
76
- def initialize: (?untyped output, ?Integer maxwidth, ?String newline, ?^(Integer) -> Integer genspace) -> void
90
+ def initialize: (?untyped output, ?Integer maxwidth, ?String newline, ?^(Integer) -> Integer genspace) -> void
77
91
 
92
+ # <!-- rdoc-file=lib/prettyprint.rb -->
78
93
  # The output object.
79
94
  #
80
95
  # This defaults to '', and should accept the << method
96
+ #
81
97
  attr_reader output: _Output
82
98
 
99
+ # <!-- rdoc-file=lib/prettyprint.rb -->
83
100
  # The maximum width of a line, before it is separated in to a newline
84
101
  #
85
- # This defaults to 79, and should be a Fixnum
102
+ # This defaults to 79, and should be an Integer
103
+ #
86
104
  attr_reader maxwidth: Integer
87
105
 
88
- # The value that is appended to +output+ to add a new line.
106
+ # <!-- rdoc-file=lib/prettyprint.rb -->
107
+ # The value that is appended to `output` to add a new line.
108
+ #
109
+ # This defaults to "n", and should be String
89
110
  #
90
- # This defaults to "\n", and should be String
91
111
  attr_reader newline: String
92
112
 
93
- # A lambda or Proc, that takes one argument, of a Fixnum, and returns
94
- # the corresponding number of spaces.
113
+ # <!-- rdoc-file=lib/prettyprint.rb -->
114
+ # A lambda or Proc, that takes one argument, of an Integer, and returns the
115
+ # corresponding number of spaces.
95
116
  #
96
117
  # By default this is:
97
- # lambda {|n| ' ' * n}
118
+ # lambda {|n| ' ' * n}
119
+ #
98
120
  attr_reader genspace: Proc
99
121
 
122
+ # <!-- rdoc-file=lib/prettyprint.rb -->
100
123
  # The number of spaces to be indented
124
+ #
101
125
  attr_reader indent: Integer
102
126
 
127
+ # <!-- rdoc-file=lib/prettyprint.rb -->
103
128
  # The PrettyPrint::GroupQueue of groups in stack to be pretty printed
129
+ #
104
130
  attr_reader group_queue: PrettyPrint::GroupQueue
105
131
 
132
+ # <!--
133
+ # rdoc-file=lib/prettyprint.rb
134
+ # - current_group()
135
+ # -->
106
136
  # Returns the group most recently added to the stack.
107
137
  #
108
138
  # Contrived example:
@@ -135,16 +165,28 @@ class PrettyPrint
135
165
  #
136
166
  def current_group: () -> PrettyPrint::Group
137
167
 
168
+ # <!--
169
+ # rdoc-file=lib/prettyprint.rb
170
+ # - break_outmost_groups()
171
+ # -->
138
172
  # Breaks the buffer into lines that are shorter than #maxwidth
139
173
  #
140
- def break_outmost_groups: () -> untyped
174
+ def break_outmost_groups: () -> untyped
141
175
 
176
+ # <!--
177
+ # rdoc-file=lib/prettyprint.rb
178
+ # - text(obj, width=obj.length)
179
+ # -->
142
180
  # This adds `obj` as a text of `width` columns in width.
143
181
  #
144
182
  # If `width` is not specified, obj.length is used.
145
183
  #
146
184
  def text: (String obj, ?Integer width) -> void
147
185
 
186
+ # <!--
187
+ # rdoc-file=lib/prettyprint.rb
188
+ # - fill_breakable(sep=' ', width=sep.length)
189
+ # -->
148
190
  # This is similar to #breakable except the decision to break or not is
149
191
  # determined individually.
150
192
  #
@@ -162,6 +204,10 @@ class PrettyPrint
162
204
  #
163
205
  def fill_breakable: (?String sep, ?Integer width) -> void
164
206
 
207
+ # <!--
208
+ # rdoc-file=lib/prettyprint.rb
209
+ # - breakable(sep=' ', width=sep.length)
210
+ # -->
165
211
  # This says "you can break a line here if necessary", and a `width`-column text
166
212
  # `sep` is inserted if a line is not broken at the point.
167
213
  #
@@ -172,6 +218,10 @@ class PrettyPrint
172
218
  #
173
219
  def breakable: (?String sep, ?Integer width) -> void
174
220
 
221
+ # <!--
222
+ # rdoc-file=lib/prettyprint.rb
223
+ # - group(indent=0, open_obj='', close_obj='', open_width=open_obj.length, close_width=close_obj.length) { || ... }
224
+ # -->
175
225
  # Groups line break hints added in the block. The line break hints are all to be
176
226
  # used or not.
177
227
  #
@@ -184,183 +234,154 @@ class PrettyPrint
184
234
  #
185
235
  def group: (?::Integer indent, ?::String open_obj, ?::String close_obj, ?Integer open_width, ?Integer close_width) { () -> untyped } -> Integer
186
236
 
237
+ # <!--
238
+ # rdoc-file=lib/prettyprint.rb
239
+ # - group_sub() { || ... }
240
+ # -->
187
241
  # Takes a block and queues a new group that is indented 1 level further.
188
242
  #
189
243
  def group_sub: () { () -> untyped } -> untyped
190
244
 
245
+ # <!--
246
+ # rdoc-file=lib/prettyprint.rb
247
+ # - nest(indent) { || ... }
248
+ # -->
191
249
  # Increases left margin after newline with `indent` for line breaks added in the
192
250
  # block.
193
251
  #
194
252
  def nest: (Integer indent) { () -> untyped } -> void
195
253
 
254
+ # <!--
255
+ # rdoc-file=lib/prettyprint.rb
256
+ # - flush()
257
+ # -->
196
258
  # outputs buffered data.
197
259
  #
198
260
  def flush: () -> Integer
199
261
 
200
262
  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
263
  def initialize: () -> void
211
264
 
212
- # The total width of the objects included in this Text object.
213
265
  attr_reader width: Integer
214
266
 
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
267
  def output: (untyped `out`, untyped output_width) -> untyped
219
268
 
220
- # Include +obj+ in the objects to be pretty printed, and increment
221
- # this Text object's total width by +width+
222
269
  def add: (untyped obj, Integer width) -> void
223
270
  end
224
271
 
225
272
  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
273
  def initialize: (String sep, Integer width, PrettyPrint q) -> void
233
274
 
234
- # Holds the separator String
235
- #
236
- # The +sep+ argument from ::new
237
275
  attr_reader obj: String
238
276
 
239
- # The width of +obj+ / +sep+
240
277
  attr_reader width: Integer
241
278
 
242
- # The number of spaces to indent.
243
- #
244
- # This is inferred from +q+ within PrettyPrint, passed in ::new
245
279
  attr_reader indent: Integer
246
280
 
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
281
  def output: (untyped `out`, Integer output_width) -> untyped
252
282
  end
253
283
 
254
284
  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
285
  def initialize: (untyped depth) -> void
270
286
 
271
- # This group's relation to previous groups
272
287
  attr_reader depth: untyped
273
288
 
274
- # Array to hold the Breakable objects for this Group
275
289
  attr_reader breakables: Array[PrettyPrint::Breakable]
276
290
 
277
- # Makes a break for this Group, and returns true
278
291
  def break: () -> bool
279
292
 
280
- # Boolean of whether this Group has made a break
281
293
  def break?: () -> bool
282
294
 
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
295
  def first?: () -> bool
287
296
  end
288
297
 
289
298
  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
299
  def initialize: (*untyped groups) -> void
302
300
 
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
301
  def enq: (untyped group) -> void
308
302
 
309
- # Returns the outer group of the queue
310
303
  def deq: () -> (PrettyPrint::Group | nil)
311
304
 
312
- # Remote +group+ from this queue
313
305
  def delete: (PrettyPrint::Group group) -> void
314
306
  end
315
307
 
308
+ # <!-- rdoc-file=lib/prettyprint.rb -->
316
309
  # PrettyPrint::SingleLine is used by PrettyPrint.singleline_format
317
310
  #
318
311
  # 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?
312
+ # * #text
313
+ # * #breakable
314
+ # * #nest
315
+ # * #group
316
+ # * #flush
317
+ # * #first?
318
+ #
325
319
  #
326
320
  # but instead, the output has no line breaks
327
321
  #
328
322
  class SingleLine
323
+ # <!--
324
+ # rdoc-file=lib/prettyprint.rb
325
+ # - new(output, maxwidth=nil, newline=nil)
326
+ # -->
329
327
  # Create a PrettyPrint::SingleLine object
330
328
  #
331
329
  # 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.
330
+ # * `output` - String (or similar) to store rendered text. Needs to respond to
331
+ # '<<'
332
+ # * `maxwidth` - Argument position expected to be here for compatibility.
333
+ # This argument is a noop.
334
+ #
335
+ # * `newline` - Argument position expected to be here for compatibility.
336
+ # This argument is a noop.
337
+ #
337
338
  def initialize: (String | untyped output, ?Integer? maxwidth, ?String? newline) -> void
338
339
 
339
- # Add +obj+ to the text to be output.
340
+ # <!--
341
+ # rdoc-file=lib/prettyprint.rb
342
+ # - text(obj, width=nil)
343
+ # -->
344
+ # Add `obj` to the text to be output.
345
+ #
346
+ # `width` argument is here for compatibility. It is a noop argument.
340
347
  #
341
- # +width+ argument is here for compatibility. It is a noop argument.
342
348
  def text: (String obj, ?Integer? width) -> void
343
349
 
344
- # Appends +sep+ to the text to be output. By default +sep+ is ' '
350
+ # <!--
351
+ # rdoc-file=lib/prettyprint.rb
352
+ # - breakable(sep=' ', width=nil)
353
+ # -->
354
+ # Appends `sep` to the text to be output. By default `sep` is ' '
355
+ #
356
+ # `width` argument is here for compatibility. It is a noop argument.
345
357
  #
346
- # +width+ argument is here for compatibility. It is a noop argument.
347
358
  def breakable: (?String sep, ?Integer? width) -> void
348
359
 
349
360
  def nest: (untyped indent) { () -> untyped } -> void
350
361
 
362
+ # <!--
363
+ # rdoc-file=lib/prettyprint.rb
364
+ # - group(indent=nil, open_obj='', close_obj='', open_width=nil, close_width=nil) { || ... }
365
+ # -->
351
366
  # Opens a block for grouping objects to be pretty printed.
352
367
  #
353
368
  # 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.
369
+ # * `indent` - noop argument. Present for compatibility.
370
+ # * `open_obj` - text appended before the &blok. Default is ''
371
+ # * `close_obj` - text appended after the &blok. Default is ''
372
+ # * `open_width` - noop argument. Present for compatibility.
373
+ # * `close_width` - noop argument. Present for compatibility.
374
+ #
359
375
  def group: (?Integer? indent, ?String open_obj, ?String close_obj, ?Integer? open_width, ?Integer? close_width) { () -> untyped } -> untyped
360
376
 
361
377
  def flush: () -> nil
362
378
 
379
+ # <!--
380
+ # rdoc-file=lib/prettyprint.rb
381
+ # - first?()
382
+ # -->
363
383
  # This is used as a predicate, and ought to be called first.
384
+ #
364
385
  def first?: () -> bool
365
386
  end
366
387
  end
@@ -1,23 +1,41 @@
1
+ %a{annotate:rdoc:skip}
1
2
  class Integer
3
+ # <!--
4
+ # rdoc-file=lib/prime.rb
5
+ # - each_prime(ubound) { |prime| ... }
6
+ # -->
2
7
  # Iterates the given block over all prime numbers.
3
8
  #
4
- # See Prime#each for more details.
9
+ # See `Prime`#each for more details.
5
10
  #
6
11
  def self.each_prime: (Integer) { (Integer) -> void } -> void
7
12
 
13
+ # <!--
14
+ # rdoc-file=lib/prime.rb
15
+ # - from_prime_division(pd)
16
+ # -->
8
17
  # Re-composes a prime factorization and returns the product.
9
18
  #
10
19
  # See Prime#int_from_prime_division for more details.
11
20
  #
12
21
  def self.from_prime_division: (Array[[ String ]]) -> Integer
13
22
 
23
+ # <!--
24
+ # rdoc-file=lib/prime.rb
25
+ # - prime_division(generator = Prime::Generator23.new)
26
+ # -->
14
27
  # Returns the factorization of `self`.
15
28
  #
16
29
  # See Prime#prime_division for more details.
17
30
  #
18
31
  def prime_division: (?Prime::PseudoPrimeGenerator) -> Array[[ Integer, Integer ]]
19
32
 
20
- # Returns true if `self` is a prime number, else returns false.
33
+ # <!--
34
+ # rdoc-file=lib/prime.rb
35
+ # - prime?()
36
+ # -->
37
+ # Returns true if `self` is a prime number, else returns false. Not recommended
38
+ # for very big integers (> 10**23).
21
39
  #
22
40
  def prime?: () -> bool
23
41
  end
@@ -1,3 +1,4 @@
1
+ # <!-- rdoc-file=lib/prime.rb -->
1
2
  # The set of all prime numbers.
2
3
  #
3
4
  # ## Example
@@ -30,7 +31,7 @@
30
31
  # few implementations of generator.
31
32
  #
32
33
  # `Prime`::`EratosthenesGenerator`
33
- # : Uses eratosthenes' sieve.
34
+ # : Uses Eratosthenes' sieve.
34
35
  # `Prime`::`TrialDivisionGenerator`
35
36
  # : Uses the trial division method.
36
37
  # `Prime`::`Generator23`
@@ -40,7 +41,6 @@
40
41
  # for factorizing an integer which is not large but has many prime factors.
41
42
  # e.g. for Prime#prime? .
42
43
  #
43
- #
44
44
  class Prime
45
45
  include Singleton
46
46
 
@@ -48,6 +48,10 @@ class Prime
48
48
 
49
49
  extend Enumerable[Integer]
50
50
 
51
+ # <!--
52
+ # rdoc-file=lib/prime.rb
53
+ # - each(ubound = nil, generator = EratosthenesGenerator.new, &block)
54
+ # -->
51
55
  # Iterates the given block over all prime numbers.
52
56
  #
53
57
  # ## Parameters
@@ -75,24 +79,38 @@ class Prime
75
79
  def self?.each: (?Integer? ubound, ?PseudoPrimeGenerator generator) { (Integer) -> void } -> void
76
80
  | (?Integer? ubound, ?PseudoPrimeGenerator generator) -> PseudoPrimeGenerator
77
81
 
82
+ # <!--
83
+ # rdoc-file=lib/prime.rb
84
+ # - int_from_prime_division(pd)
85
+ # -->
78
86
  # Re-composes a prime factorization and returns the product.
79
87
  #
88
+ # For the decomposition:
89
+ #
90
+ # [[p_1, e_1], [p_2, e_2], ..., [p_n, e_n]],
91
+ #
92
+ # it returns:
93
+ #
94
+ # p_1**e_1 * p_2**e_2 * ... * p_n**e_n.
95
+ #
80
96
  # ## Parameters
81
97
  # `pd`
82
- # : Array of pairs of integers. The each internal pair consists of a prime
83
- # number -- a prime factor -- and a natural number -- an exponent.
98
+ # : Array of pairs of integers. Each pair consists of a prime number -- a
99
+ # prime factor -- and a natural number -- its exponent (multiplicity).
84
100
  #
85
101
  #
86
102
  # ## Example
87
- # For `[[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]]`, it returns:
88
- #
89
- # p_1**e_1 * p_2**e_2 * .... * p_n**e_n.
90
- #
91
- # Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
103
+ # Prime.int_from_prime_division([[3, 2], [5, 1]]) #=> 45
104
+ # 3**2 * 5 #=> 45
92
105
  #
93
106
  def self?.int_from_prime_division: (Array[[ Integer, Integer ]]) -> Integer
94
107
 
95
- # Returns true if `value` is a prime number, else returns false.
108
+ # <!--
109
+ # rdoc-file=lib/prime.rb
110
+ # - prime?(value, generator = Prime::Generator23.new)
111
+ # -->
112
+ # Returns true if `value` is a prime number, else returns false. Integer#prime?
113
+ # is much more performant.
96
114
  #
97
115
  # ## Parameters
98
116
  #
@@ -103,15 +121,30 @@ class Prime
103
121
  #
104
122
  def self?.prime?: (Integer value, ?PseudoPrimeGenerator generator) -> bool
105
123
 
124
+ # <!--
125
+ # rdoc-file=lib/prime.rb
126
+ # - prime_division(value, generator = Prime::Generator23.new)
127
+ # -->
106
128
  # Returns the factorization of `value`.
107
129
  #
130
+ # For an arbitrary integer:
131
+ #
132
+ # p_1**e_1 * p_2**e_2 * ... * p_n**e_n,
133
+ #
134
+ # prime_division returns an array of pairs of integers:
135
+ #
136
+ # [[p_1, e_1], [p_2, e_2], ..., [p_n, e_n]].
137
+ #
138
+ # Each pair consists of a prime number -- a prime factor -- and a natural number
139
+ # -- its exponent (multiplicity).
140
+ #
108
141
  # ## Parameters
109
142
  # `value`
110
143
  # : An arbitrary integer.
111
144
  # `generator`
112
145
  # : Optional. A pseudo-prime generator. `generator`.succ must return the next
113
- # pseudo-prime number in the ascending order. It must generate all prime
114
- # numbers, but may also generate non prime numbers too.
146
+ # pseudo-prime number in ascending order. It must generate all prime
147
+ # numbers, but may also generate non-prime numbers, too.
115
148
  #
116
149
  #
117
150
  # ### Exceptions
@@ -120,15 +153,9 @@ class Prime
120
153
  #
121
154
  #
122
155
  # ## Example
123
- # For an arbitrary integer:
124
- #
125
- # n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
126
156
  #
127
- # prime_division(n) returns:
128
- #
129
- # [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
130
- #
131
- # Prime.prime_division(12) #=> [[2,2], [3,1]]
157
+ # Prime.prime_division(45) #=> [[3, 2], [5, 1]]
158
+ # 3**2 * 5 #=> 45
132
159
  #
133
160
  def self?.prime_division: (Integer, ?PseudoPrimeGenerator generator) -> Array[[ Integer, Integer ]]
134
161
 
@@ -136,33 +163,70 @@ class Prime
136
163
  #
137
164
  def self.instance: () -> Prime
138
165
 
166
+ # <!-- rdoc-file=lib/prime.rb -->
139
167
  # An abstract class for enumerating pseudo-prime numbers.
140
168
  #
141
169
  # Concrete subclasses should override succ, next, rewind.
142
170
  #
143
171
  class PseudoPrimeGenerator
172
+ # <!--
173
+ # rdoc-file=lib/prime.rb
174
+ # - new(ubound = nil)
175
+ # -->
176
+ #
144
177
  def initialize: (?Integer?) -> void
145
178
 
146
179
  include Enumerable[Integer]
147
180
 
148
- attr_accessor upper_bound (): Integer?
181
+ # <!--
182
+ # rdoc-file=lib/prime.rb
183
+ # - upper_bound()
184
+ # -->
185
+ # ----
186
+ # <!--
187
+ # rdoc-file=lib/prime.rb
188
+ # - upper_bound=(ubound)
189
+ # -->
190
+ #
191
+ attr_accessor upper_bound(): Integer?
149
192
 
193
+ # <!--
194
+ # rdoc-file=lib/prime.rb
195
+ # - each() { |prime| ... }
196
+ # -->
150
197
  # Iterates the given block for each prime number.
151
198
  #
152
199
  def each: () { (Integer) -> void } -> void
153
200
 
201
+ # <!--
202
+ # rdoc-file=lib/prime.rb
203
+ # - next()
204
+ # -->
154
205
  # alias of `succ`.
155
206
  #
156
207
  def next: () -> Integer
157
208
 
209
+ # <!--
210
+ # rdoc-file=lib/prime.rb
211
+ # - rewind()
212
+ # -->
158
213
  # Rewinds the internal position for enumeration.
159
214
  #
160
215
  # See `Enumerator`#rewind.
161
216
  #
162
217
  def rewind: () -> void
163
218
 
219
+ # <!--
220
+ # rdoc-file=lib/prime.rb
221
+ # - size()
222
+ # -->
223
+ #
164
224
  def size: () -> Float
165
225
 
226
+ # <!--
227
+ # rdoc-file=lib/prime.rb
228
+ # - succ()
229
+ # -->
166
230
  # returns the next pseudo-prime number, and move the internal position forward.
167
231
  #
168
232
  # `PseudoPrimeGenerator`#succ raises `NotImplementedError`.
@@ -170,6 +234,7 @@ class Prime
170
234
  def succ: () -> Integer
171
235
  end
172
236
 
237
+ # <!-- rdoc-file=lib/prime.rb -->
173
238
  # An implementation of `PseudoPrimeGenerator`.
174
239
  #
175
240
  # Uses `EratosthenesSieve`.
@@ -177,12 +242,14 @@ class Prime
177
242
  class EratosthenesGenerator < PseudoPrimeGenerator
178
243
  end
179
244
 
245
+ # <!-- rdoc-file=lib/prime.rb -->
180
246
  # An implementation of `PseudoPrimeGenerator` which uses a prime table generated
181
247
  # by trial division.
182
248
  #
183
249
  class TrialDivisionGenerator < PseudoPrimeGenerator
184
250
  end
185
251
 
252
+ # <!-- rdoc-file=lib/prime.rb -->
186
253
  # Generates all integers which are greater than 2 and are not divisible by
187
254
  # either 2 or 3.
188
255
  #