rbs 0.13.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +9 -5
  3. data/.gitignore +0 -1
  4. data/CHANGELOG.md +38 -2
  5. data/Gemfile +4 -0
  6. data/README.md +9 -3
  7. data/Rakefile +19 -1
  8. data/Steepfile +1 -1
  9. data/bin/annotate-with-rdoc +1 -1
  10. data/bin/setup +0 -2
  11. data/bin/test_runner.rb +15 -1
  12. data/{stdlib/builtin → core}/array.rbs +124 -120
  13. data/{stdlib/builtin → core}/basic_object.rbs +54 -54
  14. data/{stdlib/builtin → core}/binding.rbs +42 -42
  15. data/core/builtin.rbs +70 -0
  16. data/{stdlib/builtin → core}/class.rbs +33 -33
  17. data/{stdlib/builtin → core}/comparable.rbs +0 -0
  18. data/{stdlib/builtin → core}/complex.rbs +90 -90
  19. data/{stdlib/builtin → core}/constants.rbs +0 -0
  20. data/{stdlib/builtin → core}/data.rbs +0 -0
  21. data/{stdlib/builtin → core}/deprecated.rbs +0 -0
  22. data/{stdlib/builtin → core}/dir.rbs +1 -1
  23. data/{stdlib/builtin → core}/encoding.rbs +33 -33
  24. data/{stdlib/builtin → core}/enumerable.rbs +99 -92
  25. data/{stdlib/builtin → core}/enumerator.rbs +40 -40
  26. data/{stdlib/builtin → core}/errno.rbs +0 -0
  27. data/{stdlib/builtin → core}/errors.rbs +2 -2
  28. data/{stdlib/builtin → core}/exception.rbs +50 -50
  29. data/{stdlib/builtin → core}/false_class.rbs +6 -6
  30. data/{stdlib/builtin → core}/fiber.rbs +14 -14
  31. data/{stdlib/builtin → core}/fiber_error.rbs +1 -1
  32. data/{stdlib/builtin → core}/file.rbs +0 -0
  33. data/{stdlib/builtin → core}/file_test.rbs +0 -0
  34. data/{stdlib/builtin → core}/float.rbs +161 -161
  35. data/{stdlib/builtin → core}/gc.rbs +3 -3
  36. data/{stdlib/builtin → core}/hash.rbs +15 -15
  37. data/{stdlib/builtin → core}/integer.rbs +0 -0
  38. data/{stdlib/builtin → core}/io.rbs +89 -89
  39. data/{stdlib/builtin → core}/kernel.rbs +70 -154
  40. data/{stdlib/builtin → core}/marshal.rbs +0 -0
  41. data/{stdlib/builtin → core}/match_data.rbs +1 -1
  42. data/{stdlib/builtin → core}/math.rbs +0 -0
  43. data/{stdlib/builtin → core}/method.rbs +19 -19
  44. data/{stdlib/builtin → core}/module.rbs +13 -13
  45. data/{stdlib/builtin → core}/nil_class.rbs +20 -20
  46. data/{stdlib/builtin → core}/numeric.rbs +101 -101
  47. data/{stdlib/builtin → core}/object.rbs +173 -173
  48. data/core/object_space.rbs +98 -0
  49. data/{stdlib/builtin → core}/proc.rbs +91 -91
  50. data/{stdlib/builtin → core}/process.rbs +0 -0
  51. data/{stdlib/builtin → core}/random.rbs +1 -1
  52. data/{stdlib/builtin → core}/range.rbs +4 -6
  53. data/{stdlib/builtin → core}/rational.rbs +83 -83
  54. data/{stdlib/builtin → core}/rb_config.rbs +0 -0
  55. data/{stdlib/builtin → core}/regexp.rbs +0 -0
  56. data/{stdlib/builtin → core}/ruby_vm.rbs +0 -0
  57. data/{stdlib/builtin → core}/signal.rbs +7 -7
  58. data/{stdlib/builtin → core}/string.rbs +10 -10
  59. data/{stdlib/builtin → core}/string_io.rbs +8 -8
  60. data/{stdlib/builtin → core}/struct.rbs +2 -2
  61. data/{stdlib/builtin → core}/symbol.rbs +1 -1
  62. data/{stdlib/builtin → core}/thread.rbs +189 -189
  63. data/{stdlib/builtin → core}/thread_group.rbs +2 -2
  64. data/{stdlib/builtin → core}/time.rbs +0 -0
  65. data/{stdlib/builtin → core}/trace_point.rbs +0 -0
  66. data/{stdlib/builtin → core}/true_class.rbs +10 -10
  67. data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
  68. data/{stdlib/builtin → core}/warning.rbs +1 -1
  69. data/docs/CONTRIBUTING.md +1 -0
  70. data/docs/repo.md +125 -0
  71. data/docs/syntax.md +50 -6
  72. data/goodcheck.yml +22 -5
  73. data/lib/rbs.rb +1 -0
  74. data/lib/rbs/ast/comment.rb +1 -1
  75. data/lib/rbs/cli.rb +105 -103
  76. data/lib/rbs/definition.rb +9 -4
  77. data/lib/rbs/definition_builder.rb +54 -22
  78. data/lib/rbs/environment.rb +1 -1
  79. data/lib/rbs/environment_loader.rb +79 -105
  80. data/lib/rbs/environment_walker.rb +58 -29
  81. data/lib/rbs/namespace.rb +1 -1
  82. data/lib/rbs/parser.rb +3153 -0
  83. data/lib/rbs/parser.y +25 -11
  84. data/lib/rbs/prototype/rb.rb +186 -25
  85. data/lib/rbs/prototype/runtime.rb +18 -7
  86. data/lib/rbs/repository.rb +121 -0
  87. data/lib/rbs/test/hook.rb +27 -15
  88. data/lib/rbs/test/setup.rb +5 -3
  89. data/lib/rbs/test/setup_helper.rb +4 -4
  90. data/lib/rbs/test/tester.rb +4 -1
  91. data/lib/rbs/test/type_check.rb +18 -7
  92. data/lib/rbs/type_name.rb +3 -2
  93. data/lib/rbs/variance_calculator.rb +1 -1
  94. data/lib/rbs/vendorer.rb +38 -16
  95. data/lib/rbs/version.rb +1 -1
  96. data/lib/rbs/writer.rb +1 -1
  97. data/sig/cli.rbs +58 -0
  98. data/sig/constant.rbs +2 -2
  99. data/sig/constant_table.rbs +11 -11
  100. data/sig/declarations.rbs +2 -2
  101. data/sig/definition.rbs +10 -5
  102. data/sig/definition_builder.rbs +4 -1
  103. data/sig/environment_loader.rbs +92 -46
  104. data/sig/members.rbs +2 -2
  105. data/sig/method_types.rbs +1 -1
  106. data/sig/namespace.rbs +4 -4
  107. data/sig/parser.rbs +25 -0
  108. data/sig/polyfill.rbs +42 -0
  109. data/sig/rbs.rbs +8 -0
  110. data/sig/repository.rbs +79 -0
  111. data/sig/substitution.rbs +3 -3
  112. data/sig/typename.rbs +1 -1
  113. data/sig/types.rbs +1 -1
  114. data/sig/vendorer.rbs +44 -0
  115. data/sig/writer.rbs +15 -15
  116. data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
  117. data/stdlib/base64/{base64.rbs → 0/base64.rbs} +1 -1
  118. data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +2 -2
  119. data/stdlib/{bigdecimal/math → bigdecimal-math/0}/big_math.rbs +0 -0
  120. data/stdlib/bigdecimal/{big_decimal.rbs → 0/big_decimal.rbs} +0 -0
  121. data/stdlib/coverage/{coverage.rbs → 0/coverage.rbs} +2 -2
  122. data/stdlib/csv/{csv.rbs → 0/csv.rbs} +4 -4
  123. data/stdlib/date/{date.rbs → 0/date.rbs} +4 -4
  124. data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +1 -1
  125. data/stdlib/dbm/0/dbm.rbs +277 -0
  126. data/stdlib/erb/{erb.rbs → 0/erb.rbs} +0 -0
  127. data/stdlib/fiber/{fiber.rbs → 0/fiber.rbs} +0 -0
  128. data/stdlib/find/{find.rbs → 0/find.rbs} +12 -12
  129. data/stdlib/forwardable/{forwardable.rbs → 0/forwardable.rbs} +0 -0
  130. data/stdlib/ipaddr/{ipaddr.rbs → 0/ipaddr.rbs} +0 -0
  131. data/stdlib/json/{json.rbs → 0/json.rbs} +0 -0
  132. data/stdlib/logger/{formatter.rbs → 0/formatter.rbs} +0 -0
  133. data/stdlib/logger/{log_device.rbs → 0/log_device.rbs} +1 -1
  134. data/stdlib/logger/{logger.rbs → 0/logger.rbs} +1 -1
  135. data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
  136. data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
  137. data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
  138. data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +40 -40
  139. data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
  140. data/stdlib/prime/{prime.rbs → 0/prime.rbs} +1 -1
  141. data/stdlib/pstore/0/pstore.rbs +287 -0
  142. data/stdlib/pty/{pty.rbs → 0/pty.rbs} +1 -1
  143. data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
  144. data/stdlib/set/{set.rbs → 0/set.rbs} +10 -10
  145. data/stdlib/singleton/0/singleton.rbs +111 -0
  146. data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +12 -12
  147. data/stdlib/tsort/0/cyclic.rbs +4 -0
  148. data/stdlib/tsort/0/interfaces.rbs +19 -0
  149. data/stdlib/tsort/0/tsort.rbs +363 -0
  150. data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
  151. data/stdlib/uri/{generic.rbs → 0/generic.rbs} +1 -1
  152. data/stdlib/uri/{http.rbs → 0/http.rbs} +0 -0
  153. data/stdlib/uri/{https.rbs → 0/https.rbs} +0 -0
  154. data/stdlib/uri/{ldap.rbs → 0/ldap.rbs} +0 -0
  155. data/stdlib/uri/{ldaps.rbs → 0/ldaps.rbs} +0 -0
  156. data/stdlib/yaml/0/dbm.rbs +221 -0
  157. data/stdlib/yaml/0/store.rbs +53 -0
  158. data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
  159. data/steep/Gemfile.lock +9 -9
  160. metadata +109 -94
  161. data/stdlib/builtin/builtin.rbs +0 -42
@@ -1,3 +1,11 @@
1
1
  module RBS
2
2
  def self.logger: () -> Logger
3
+
4
+ def self.logger_level: () -> untyped
5
+
6
+ def self.logger_level=: (untyped) -> untyped
7
+
8
+ def self.logger_output: () -> IO
9
+
10
+ def self.logger_output=: (IO) -> IO
3
11
  end
@@ -0,0 +1,79 @@
1
+ module RBS
2
+ # Set of RBS repositories.
3
+ #
4
+ # A repository object can handle multiple repository roots.
5
+ #
6
+ # repo = RBS::Repository.new()
7
+ # repo.add(Pathname("vendor/rbs/gem-rbs"))
8
+ # repo.add(Pathname("vendor/rbs/internal-rbs"))
9
+ # repo.add(Pathname("vendor/rbs/definitely-rbs"))
10
+ #
11
+ # repo.lookup("minitest", "2.1.3") => Pathname or nil
12
+ #
13
+ # If one gem version can resolve to several directories, the last added dir wins.
14
+ #
15
+ class Repository
16
+ class GemRBS
17
+ attr_reader name: String
18
+
19
+ # Array of gem dirs.
20
+ # Gem dir contains directories for each version.
21
+ attr_reader paths: Array[Pathname]
22
+
23
+ # Hash from a version to VersionPath object.
24
+ attr_reader versions(): Hash[Gem::Version, VersionPath]
25
+
26
+ @versions: Hash[Gem::Version, VersionPath]?
27
+
28
+ def initialize: (name: String) -> void
29
+
30
+ def load!: () -> void
31
+
32
+ def version_names: () -> Array[Gem::Version]
33
+
34
+ def oldest_version: () -> VersionPath
35
+
36
+ def latest_version: () -> VersionPath
37
+
38
+ def find_best_version: (Gem::Version?) -> VersionPath
39
+
40
+ # Returns true if versions is empty.
41
+ def empty?: () -> bool
42
+ end
43
+
44
+ class VersionPath
45
+ attr_reader gem: GemRBS
46
+ attr_reader version: Gem::Version
47
+ attr_reader path: Pathname
48
+
49
+ def initialize: (gem: GemRBS, version: Gem::Version, path: Pathname) -> void
50
+ end
51
+
52
+ DEFAULT_STDLIB_ROOT: Pathname
53
+
54
+ # Array of _root dir_s of repositories.
55
+ #
56
+ attr_reader dirs: Array[Pathname]
57
+
58
+ attr_reader gems: Hash[String, GemRBS]
59
+
60
+ # An optional keyword argument `no_stdlib` is to skip adding directory for stdlib classes.
61
+ # Passing truthy value will skip loading stdlib. (You can add the stdlib root by yourself.)
62
+ #
63
+ def initialize: (?no_stdlib: bool) -> void
64
+
65
+ # Add new _root dir_ to the repository set.
66
+ # If two repository dirs have exactly same gem-version definitions, the latter overwrites the prior.
67
+ #
68
+ def add: (Pathname dir) -> void
69
+
70
+ # Returns a directory for given `gem` name and `version`.
71
+ # `version` can be `nil` for _any version_.
72
+ #
73
+ # If the given gem cannot be found, it returns `nil`.
74
+ #
75
+ def lookup: (String gem, String? version) -> Pathname?
76
+
77
+ def lookup_path: (String gem, String? version) -> [GemRBS, VersionPath]?
78
+ end
79
+ end
@@ -1,6 +1,6 @@
1
1
  module RBS
2
2
  # Substitution from type variables to types.
3
- #
3
+ #
4
4
  # The substitution construction is in _destructive_ manner.
5
5
  #
6
6
  # sub = Substitution.new
@@ -25,7 +25,7 @@ module RBS
25
25
  # Utility method to construct a substitution.
26
26
  # Raises an error when `variables.size != types.size`.
27
27
  # `instance_type` defaults to `nil`.
28
- #
28
+ #
29
29
  # Yields types in `types` and the block value is used if block is given.
30
30
  #
31
31
  def self.build: (Array[Symbol] variables, Array[Types::t] types, ?instance_type: Types::t?) ?{ (Types::t) -> Types::t } -> instance
@@ -36,4 +36,4 @@ module RBS
36
36
  # Returns a substitution without variables given in `vars`.
37
37
  def without: (*Symbol vars) -> Substitution
38
38
  end
39
- end
39
+ end
@@ -1,6 +1,6 @@
1
1
  module RBS
2
2
  # TypeName represents name of types in RBS.
3
- #
3
+ #
4
4
  # TypeNames are one of the three kind, class, alias, and interface.
5
5
  # *class* type names corresponds to Ruby classes and modules.
6
6
  # There are no corresponding Ruby value to *alias* and *interface* type names.
@@ -154,7 +154,7 @@ module RBS
154
154
 
155
155
  include NoFreeVariables
156
156
  include NoSubst
157
- include EmptyEachType
157
+ include EmptyEachType
158
158
  end
159
159
 
160
160
  module Application
@@ -0,0 +1,44 @@
1
+ module RBS
2
+ # Copies RBS files loaded through `loader` under `vendor_dir`.
3
+ #
4
+ # Core libraries and library RBS files will be copied.
5
+ #
6
+ # loader = RBS::EnvironmentLoader.new()
7
+ #
8
+ # loader.add(library: set) # Libraries will be copied.
9
+ # loader.add(library: "minitest", version: "1.2.3")
10
+ #
11
+ # loader.add(path: Pathname("sig")) # Dirs will be ignored.
12
+ #
13
+ # vendorer = RBS::Vendorer.new(vendor_dir: Pathname("vendor/rbs"), loader: loader)
14
+ # vendorer.clearn!
15
+ # vendorer.copy!
16
+ #
17
+ # The result will be:
18
+ # vendor/rbs/core => Will include core RBSs
19
+ # vendor/rbs/set-0 => Will include `set` library RBSs.
20
+ # vendor/rbs/minitest-1.2.3 => Will include `minitest` library RBSs.
21
+ #
22
+ # The vendorerd RBSs will be loaded through :dir source.
23
+ #
24
+ # loader = RBS::EnvironmentLoader.new(core_root: nil, repository: RBS::Repository.new(no_stdlib: true))
25
+ # loader.add(path: Pathname("vendor/rbs"))
26
+ # loader.add(path: Pathname("sig"))
27
+ #
28
+ class Vendorer
29
+ attr_reader vendor_dir: Pathname
30
+ attr_reader loader: EnvironmentLoader
31
+
32
+ def initialize: (vendor_dir: Pathname, loader: EnvironmentLoader) -> void
33
+
34
+ # Copy RBS files into `vendor_dir`.
35
+ # Ensures the `vendor_dir` exists.
36
+ def copy!: () -> void
37
+
38
+ # Deletes `vendor_dir` and its content if exists.
39
+ #
40
+ def clean!: () -> void
41
+
42
+ def ensure_dir: [A] () { () -> A } -> A
43
+ end
44
+ end
@@ -4,37 +4,37 @@ module RBS
4
4
  attr_reader indentation: Array[String]
5
5
 
6
6
  def initialize: (out: IO) -> void
7
-
7
+
8
8
  def indent: (?Integer size) { () -> void } -> void
9
-
9
+
10
10
  def prefix: () -> String
11
-
11
+
12
12
  def puts: (?String) -> void
13
-
13
+
14
14
  def write_annotation: (Array[AST::Annotation]) -> void
15
-
15
+
16
16
  def write_comment: (AST::Comment?) -> void
17
-
17
+
18
18
  def write: (Array[AST::Declarations::t]) -> void
19
-
19
+
20
20
  def write_decl: (AST::Declarations::t) -> void
21
-
21
+
22
22
  def write_member: (AST::Declarations::Module::member) -> void
23
-
23
+
24
24
  def name_and_params: (TypeName, AST::Declarations::ModuleTypeParams) -> String?
25
-
25
+
26
26
  def name_and_args: (TypeName, Array[Types::t]) -> String?
27
-
27
+
28
28
  def method_name: (Symbol) -> String
29
-
29
+
30
30
  def write_def: (AST::Members::MethodDefinition) -> void
31
-
31
+
32
32
  def attribute: (:reader | :writer | :accessor, AST::Members::Attribute) -> void
33
-
33
+
34
34
  interface _Located
35
35
  def location: () -> Location?
36
36
  end
37
-
37
+
38
38
  def preserve_empty_line: (_Located?, _Located) -> void
39
39
  end
40
40
  end
@@ -67,5 +67,5 @@ module Base64
67
67
  # 64 Encoding with URL and Filename Safe Alphabet'' in RFC 4648. The alphabet
68
68
  # uses '-' instead of '+' and '_' instead of '/'. Note that the result can still
69
69
  # contain '='. You can remove the padding by setting `padding` as false.
70
- def self?.urlsafe_encode64: (String bin, ?padding: bool) -> String
70
+ def self?.urlsafe_encode64: (String bin, ?padding: boolish) -> String
71
71
  end
@@ -53,9 +53,9 @@
53
53
  # times: 1.000000 0.000000 1.000000 ( 1.003611)
54
54
  # upto: 1.030000 0.000000 1.030000 ( 1.028098)
55
55
  #
56
- # * The times for some benchmarks depend on the order in which items are run.
56
+ # * The times for some benchmarks depend on the order in which items are run.
57
57
  # These differences are due to the cost of memory allocation and garbage
58
- # collection. To avoid these discrepancies, the #bmbm method is provided.
58
+ # collection. To avoid these discrepancies, the #bmbm method is provided.
59
59
  # For example, to compare ways to sort an array of floats:
60
60
  #
61
61
  # require 'benchmark'
@@ -49,7 +49,7 @@ module Coverage
49
49
  # `clear` is true, it clears the counters to zero. If `stop` is true, it
50
50
  # disables coverage measurement.
51
51
  #
52
- def self.result: (?stop: bool, ?clear: bool) -> Hash[String, untyped]
52
+ def self.result: (?stop: boolish, ?clear: boolish) -> Hash[String, untyped]
53
53
 
54
54
  # Returns true if coverage stats are currently being collected (after
55
55
  # Coverage.start call, but before Coverage.result call)
@@ -58,5 +58,5 @@ module Coverage
58
58
 
59
59
  # Enables coverage measurement.
60
60
  #
61
- def self.start: (?lines: bool, ?branches: bool, ?methods: bool, ?oneshot_lines: bool) -> nil
61
+ def self.start: (?lines: boolish, ?branches: boolish, ?methods: boolish, ?oneshot_lines: boolish) -> nil
62
62
  end
@@ -159,7 +159,7 @@
159
159
  # with it.
160
160
  #
161
161
  class CSV < Object
162
- include Enumerable[untyped, untyped]
162
+ include Enumerable[untyped]
163
163
 
164
164
  # This method is intended as the primary interface for reading CSV files. You
165
165
  # pass a `path` and any `options` you wish to set for the read. Each row of file
@@ -407,7 +407,7 @@ CSV::VERSION: String
407
407
  # processing is activated.
408
408
  #
409
409
  class CSV::Row < Object
410
- include Enumerable[untyped, untyped]
410
+ include Enumerable[untyped]
411
411
 
412
412
  # If a two-element Array is provided, it is assumed to be a header and field and
413
413
  # the pair is appended. A Hash works the same way with the key being the header
@@ -578,7 +578,7 @@ end
578
578
  # processing is activated.
579
579
  #
580
580
  class CSV::Table[out Elem] < Object
581
- include Enumerable[untyped, untyped]
581
+ include Enumerable[untyped]
582
582
 
583
583
  # Constructs a new CSV::Table from `array_of_rows`, which are expected to be
584
584
  # CSV::Row objects. All rows are assumed to have the same headers.
@@ -755,7 +755,7 @@ class CSV::Table[out Elem] < Object
755
755
  # This method assumes you want the Table.headers(), unless you explicitly pass
756
756
  # `:write_headers => false`.
757
757
  #
758
- def to_csv: (?write_headers: bool, **untyped) -> untyped
758
+ def to_csv: (?write_headers: boolish, **untyped) -> untyped
759
759
 
760
760
  alias to_s to_csv
761
761
 
@@ -178,7 +178,7 @@ class Date
178
178
  #
179
179
  # Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
180
180
  #
181
- def self._parse: (String str, ?bool complete) -> Hash[Symbol, Integer]
181
+ def self._parse: (String str, ?boolish complete) -> Hash[Symbol, Integer]
182
182
 
183
183
  # Returns a hash of parsed elements.
184
184
  #
@@ -318,7 +318,7 @@ class Date
318
318
  #
319
319
  def self.ordinal: (?Integer year, ?Integer yday, ?Integer start) -> Date
320
320
 
321
- # Parses the given representation of date and time, and creates a date object.
321
+ # Parses the given representation of date and time, and creates a date object.
322
322
  # This method does not function as a validator.
323
323
  #
324
324
  # If the optional second argument is true and the detected year is in the range
@@ -328,7 +328,7 @@ class Date
328
328
  # Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
329
329
  # Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
330
330
  #
331
- def self.parse: (String str, ?bool complete, ?Integer start) -> Date
331
+ def self.parse: (String str, ?boolish complete, ?Integer start) -> Date
332
332
 
333
333
  # Creates a new Date object by parsing from a string according to some typical
334
334
  # RFC 2822 formats.
@@ -448,7 +448,7 @@ class Date
448
448
  #
449
449
  def +: (Integer | Rational other) -> Date
450
450
 
451
- # Returns the difference between the two dates if the other is a date object.
451
+ # Returns the difference between the two dates if the other is a date object.
452
452
  # If the other is a numeric value, returns a date object pointing `other` days
453
453
  # before self. If the other is a fractional number, assumes its precision is at
454
454
  # most nanosecond.
@@ -236,7 +236,7 @@ class DateTime < Date
236
236
  # DateTime.parse('3rd Feb 2001 04:05:06 PM')
237
237
  # #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
238
238
  #
239
- def self.parse: (String str, ?bool complete, ?Integer start) -> DateTime
239
+ def self.parse: (String str, ?boolish complete, ?Integer start) -> DateTime
240
240
 
241
241
  # Creates a new DateTime object by parsing from a string according to some
242
242
  # typical RFC 2822 formats.
@@ -0,0 +1,277 @@
1
+ # ## Introduction
2
+ #
3
+ # The DBM class provides a wrapper to a Unix-style
4
+ # [dbm](http://en.wikipedia.org/wiki/Dbm) or Database Manager library.
5
+ #
6
+ # Dbm databases do not have tables or columns; they are simple key-value data
7
+ # stores, like a Ruby Hash except not resident in RAM. Keys and values must be
8
+ # strings.
9
+ #
10
+ # The exact library used depends on how Ruby was compiled. It could be any of
11
+ # the following:
12
+ #
13
+ # * The original ndbm library is released in 4.3BSD. It is based on dbm
14
+ # library in Unix Version 7 but has different API to support multiple
15
+ # databases in a process.
16
+ # * [Berkeley DB](http://en.wikipedia.org/wiki/Berkeley_DB) versions 1 thru 6,
17
+ # also known as BDB and Sleepycat DB, now owned by Oracle Corporation.
18
+ # * Berkeley DB 1.x, still found in 4.4BSD derivatives (FreeBSD, OpenBSD,
19
+ # etc).
20
+ # * [gdbm](http://www.gnu.org/software/gdbm/), the GNU implementation of dbm.
21
+ # * [qdbm](http://fallabs.com/qdbm/index.html), another open source
22
+ # reimplementation of dbm.
23
+ #
24
+ #
25
+ # All of these dbm implementations have their own Ruby interfaces available,
26
+ # which provide richer (but varying) APIs.
27
+ #
28
+ # ## Cautions
29
+ #
30
+ # Before you decide to use DBM, there are some issues you should consider:
31
+ #
32
+ # * Each implementation of dbm has its own file format. Generally, dbm
33
+ # libraries will not read each other's files. This makes dbm files a bad
34
+ # choice for data exchange.
35
+ #
36
+ # * Even running the same OS and the same dbm implementation, the database
37
+ # file format may depend on the CPU architecture. For example, files may not
38
+ # be portable between PowerPC and 386, or between 32 and 64 bit Linux.
39
+ #
40
+ # * Different versions of Berkeley DB use different file formats. A change to
41
+ # the OS may therefore break DBM access to existing files.
42
+ #
43
+ # * Data size limits vary between implementations. Original Berkeley DB was
44
+ # limited to 2GB of data. Dbm libraries also sometimes limit the total size
45
+ # of a key/value pair, and the total size of all the keys that hash to the
46
+ # same value. These limits can be as little as 512 bytes. That said, gdbm
47
+ # and recent versions of Berkeley DB do away with these limits.
48
+ #
49
+ #
50
+ # Given the above cautions, DBM is not a good choice for long term storage of
51
+ # important data. It is probably best used as a fast and easy alternative to a
52
+ # Hash for processing large amounts of data.
53
+ #
54
+ # ## Example
55
+ #
56
+ # require 'dbm'
57
+ # db = DBM.open('rfcs', 0666, DBM::WRCREAT)
58
+ # db['822'] = 'Standard for the Format of ARPA Internet Text Messages'
59
+ # db['1123'] = 'Requirements for Internet Hosts - Application and Support'
60
+ # db['3068'] = 'An Anycast Prefix for 6to4 Relay Routers'
61
+ # puts db['822']
62
+ #
63
+ class DBM
64
+ include Enumerable[untyped]
65
+
66
+ # Open a dbm database and yields it if a block is given. See also `DBM.new`.
67
+ #
68
+ def self.open: (*untyped) -> ::DBM
69
+
70
+ public
71
+
72
+ # Return a value from the database by locating the key string provided. If the
73
+ # key is not found, returns nil.
74
+ #
75
+ def []: (untyped) -> untyped
76
+
77
+ # Stores the specified string value in the database, indexed via the string key
78
+ # provided.
79
+ #
80
+ def []=: (untyped, untyped) -> untyped
81
+
82
+ # Deletes all data from the database.
83
+ #
84
+ def clear: () -> self
85
+
86
+ # Closes the database.
87
+ #
88
+ def close: () -> NilClass
89
+
90
+ # Returns true if the database is closed, false otherwise.
91
+ #
92
+ def closed?: () -> bool
93
+
94
+ # Deletes an entry from the database.
95
+ #
96
+ def delete: (untyped) -> untyped
97
+
98
+ # Deletes all entries for which the code block returns true. Returns self.
99
+ #
100
+ def delete_if: () ?{ (untyped) -> bool } -> self
101
+
102
+ # Calls the block once for each [key, value] pair in the database. Returns self.
103
+ #
104
+ def each: (?untyped, ?untyped) -> Enumerator[untyped, ::DBM]
105
+
106
+ # Calls the block once for each key string in the database. Returns self.
107
+ #
108
+ def each_key: () -> Enumerator[String, ::DBM]
109
+
110
+ # Calls the block once for each [key, value] pair in the database. Returns self.
111
+ #
112
+ def each_pair: (?untyped, ?untyped) -> Enumerator[untyped, ::DBM]
113
+
114
+ # Calls the block once for each value string in the database. Returns self.
115
+ #
116
+ def each_value: () -> Enumerator[untyped, ::DBM]
117
+
118
+ # Returns true if the database is empty, false otherwise.
119
+ #
120
+ def empty?: () -> bool
121
+
122
+ # Return a value from the database by locating the key string provided. If the
123
+ # key is not found, returns `ifnone`. If `ifnone` is not given, raises
124
+ # IndexError.
125
+ #
126
+ def fetch: (*String) -> untyped
127
+
128
+ # Returns true if the database contains the specified key, false otherwise.
129
+ #
130
+ def has_key?: (String) -> bool
131
+
132
+ # Returns true if the database contains the specified string value, false
133
+ # otherwise.
134
+ #
135
+ def has_value?: (untyped) -> bool
136
+
137
+ # Returns true if the database contains the specified key, false otherwise.
138
+ #
139
+ def include?: (String) -> bool
140
+
141
+ def index: (untyped) -> (String | NilClass)
142
+
143
+ # Returns a Hash (not a DBM database) created by using each value in the
144
+ # database as a key, with the corresponding key as its value.
145
+ #
146
+ def invert: () -> Hash[untyped, String]
147
+
148
+ # Returns the key for the specified value.
149
+ #
150
+ def key: (untyped) -> (String | NilClass)
151
+
152
+ # Returns true if the database contains the specified key, false otherwise.
153
+ #
154
+ def key?: (untyped) -> bool
155
+
156
+ # Returns an array of all the string keys in the database.
157
+ #
158
+ def keys: () -> Array[String]
159
+
160
+ # Returns the number of entries in the database.
161
+ #
162
+ def length: () -> Integer
163
+
164
+ # Returns true if the database contains the specified key, false otherwise.
165
+ #
166
+ def member?: (untyped) -> bool
167
+
168
+ # Converts the contents of the database to an in-memory Hash, then calls
169
+ # Hash#reject with the specified code block, returning a new Hash.
170
+ #
171
+ def reject: () -> Hash[untyped, untyped]
172
+
173
+ # Deletes all entries for which the code block returns true. Returns self.
174
+ #
175
+ def reject!: () { (String, untyped) -> untyped } -> self
176
+
177
+ # Replaces the contents of the database with the contents of the specified
178
+ # object. Takes any object which implements the each_pair method, including Hash
179
+ # and DBM objects.
180
+ #
181
+ def replace: (untyped) -> ::DBM
182
+
183
+ # Returns a new array consisting of the [key, value] pairs for which the code
184
+ # block returns true.
185
+ #
186
+ def select: () { () -> untyped } -> Array[untyped]
187
+
188
+ # Removes a [key, value] pair from the database, and returns it. If the database
189
+ # is empty, returns nil. The order in which values are removed/returned is not
190
+ # guaranteed.
191
+ #
192
+ def shift: () -> Array[untyped]
193
+
194
+ # Returns the number of entries in the database.
195
+ #
196
+ def size: () -> Integer
197
+
198
+ # Stores the specified string value in the database, indexed via the string key
199
+ # provided.
200
+ #
201
+ def store: (String, untyped) -> String
202
+
203
+ # Converts the contents of the database to an array of [key, value] arrays, and
204
+ # returns it.
205
+ #
206
+ def to_a: () -> Array[untyped]
207
+
208
+ # Converts the contents of the database to an in-memory Hash object, and returns
209
+ # it.
210
+ #
211
+ def to_hash: () -> Hash[String, untyped]
212
+
213
+ # Updates the database with multiple values from the specified object. Takes any
214
+ # object which implements the each_pair method, including Hash and DBM objects.
215
+ #
216
+ def update: (untyped) -> ::DBM
217
+
218
+ # Returns true if the database contains the specified string value, false
219
+ # otherwise.
220
+ #
221
+ def value?: (untyped) -> bool
222
+
223
+ # Returns an array of all the string values in the database.
224
+ #
225
+ def values: () -> Array[untyped]
226
+
227
+ # Returns an array containing the values associated with the given keys.
228
+ #
229
+ def values_at: (*String) -> Array[untyped]
230
+
231
+ private
232
+
233
+ # Open a dbm database with the specified name, which can include a directory
234
+ # path. Any file extensions needed will be supplied automatically by the dbm
235
+ # library. For example, Berkeley DB appends '.db', and GNU gdbm uses two
236
+ # physical files with extensions '.dir' and '.pag'.
237
+ #
238
+ # The mode should be an integer, as for Unix chmod.
239
+ #
240
+ # Flags should be one of READER, WRITER, WRCREAT or NEWDB.
241
+ #
242
+ def initialize: (*untyped) -> self
243
+ end
244
+
245
+ # Indicates that dbm_open() should open the database in read/write mode, create
246
+ # it if it does not already exist, and delete all contents if it does already
247
+ # exist.
248
+ #
249
+ DBM::NEWDB: Integer
250
+
251
+ # Indicates that dbm_open() should open the database in read-only mode
252
+ #
253
+ #
254
+ DBM::READER: Integer
255
+
256
+ # Identifies ndbm library version.
257
+ #
258
+ # Examples:
259
+ #
260
+ # * "ndbm (4.3BSD)"
261
+ # * "Berkeley DB 4.8.30: (April 9, 2010)"
262
+ # * "Berkeley DB (unknown)" (4.4BSD, maybe)
263
+ # * "GDBM version 1.8.3. 10/15/2002 (built Jul 1 2011 12:32:45)"
264
+ # * "QDBM 1.8.78"
265
+ #
266
+ #
267
+ DBM::VERSION: String
268
+
269
+ # Indicates that dbm_open() should open the database in read/write mode, and
270
+ # create it if it does not already exist
271
+ #
272
+ DBM::WRCREAT: Integer
273
+
274
+ # Indicates that dbm_open() should open the database in read/write mode
275
+ #
276
+ #
277
+ DBM::WRITER: Integer