rbs 4.0.0.dev.4 → 4.0.0.dev.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 (223) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -14
  3. data/.github/workflows/bundle-update.yml +60 -0
  4. data/.github/workflows/c-check.yml +11 -8
  5. data/.github/workflows/comments.yml +3 -3
  6. data/.github/workflows/dependabot.yml +1 -1
  7. data/.github/workflows/ruby.yml +17 -34
  8. data/.github/workflows/typecheck.yml +2 -2
  9. data/.github/workflows/valgrind.yml +42 -0
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +1 -1
  12. data/README.md +1 -1
  13. data/Rakefile +32 -5
  14. data/config.yml +46 -0
  15. data/core/array.rbs +96 -46
  16. data/core/binding.rbs +0 -2
  17. data/core/builtin.rbs +2 -2
  18. data/core/comparable.rbs +13 -6
  19. data/core/complex.rbs +55 -41
  20. data/core/dir.rbs +4 -4
  21. data/core/encoding.rbs +7 -10
  22. data/core/enumerable.rbs +90 -3
  23. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  24. data/core/enumerator.rbs +63 -1
  25. data/core/errno.rbs +8 -0
  26. data/core/errors.rbs +28 -1
  27. data/core/exception.rbs +2 -2
  28. data/core/fiber.rbs +40 -20
  29. data/core/file.rbs +108 -78
  30. data/core/file_test.rbs +1 -1
  31. data/core/float.rbs +225 -69
  32. data/core/gc.rbs +417 -281
  33. data/core/hash.rbs +1023 -727
  34. data/core/integer.rbs +104 -110
  35. data/core/io/buffer.rbs +21 -10
  36. data/core/io/wait.rbs +11 -33
  37. data/core/io.rbs +82 -19
  38. data/core/kernel.rbs +70 -59
  39. data/core/marshal.rbs +1 -1
  40. data/core/match_data.rbs +1 -1
  41. data/core/math.rbs +42 -3
  42. data/core/method.rbs +63 -27
  43. data/core/module.rbs +103 -26
  44. data/core/nil_class.rbs +3 -3
  45. data/core/numeric.rbs +43 -35
  46. data/core/object.rbs +3 -3
  47. data/core/object_space.rbs +21 -15
  48. data/core/pathname.rbs +1272 -0
  49. data/core/proc.rbs +30 -25
  50. data/core/process.rbs +4 -2
  51. data/core/ractor.rbs +361 -509
  52. data/core/random.rbs +17 -0
  53. data/core/range.rbs +113 -16
  54. data/core/rational.rbs +56 -85
  55. data/core/rbs/unnamed/argf.rbs +2 -2
  56. data/core/rbs/unnamed/env_class.rbs +1 -1
  57. data/core/rbs/unnamed/random.rbs +4 -113
  58. data/core/regexp.rbs +25 -20
  59. data/core/ruby.rbs +53 -0
  60. data/core/ruby_vm.rbs +6 -4
  61. data/core/rubygems/errors.rbs +3 -70
  62. data/core/rubygems/rubygems.rbs +11 -79
  63. data/core/rubygems/version.rbs +2 -3
  64. data/core/set.rbs +488 -359
  65. data/core/signal.rbs +24 -14
  66. data/core/string.rbs +3171 -1241
  67. data/core/struct.rbs +1 -1
  68. data/core/symbol.rbs +17 -11
  69. data/core/thread.rbs +95 -33
  70. data/core/time.rbs +35 -9
  71. data/core/trace_point.rbs +7 -4
  72. data/core/unbound_method.rbs +14 -6
  73. data/docs/aliases.md +79 -0
  74. data/docs/collection.md +2 -2
  75. data/docs/encoding.md +56 -0
  76. data/docs/gem.md +0 -1
  77. data/docs/inline.md +470 -0
  78. data/docs/sigs.md +3 -3
  79. data/docs/syntax.md +33 -4
  80. data/docs/type_fingerprint.md +21 -0
  81. data/exe/rbs +1 -1
  82. data/ext/rbs_extension/ast_translation.c +77 -3
  83. data/ext/rbs_extension/ast_translation.h +3 -0
  84. data/ext/rbs_extension/class_constants.c +8 -2
  85. data/ext/rbs_extension/class_constants.h +4 -0
  86. data/ext/rbs_extension/extconf.rb +5 -1
  87. data/ext/rbs_extension/legacy_location.c +5 -5
  88. data/ext/rbs_extension/main.c +37 -20
  89. data/include/rbs/ast.h +85 -38
  90. data/include/rbs/defines.h +27 -0
  91. data/include/rbs/lexer.h +30 -11
  92. data/include/rbs/parser.h +6 -6
  93. data/include/rbs/string.h +0 -2
  94. data/include/rbs/util/rbs_allocator.h +34 -13
  95. data/include/rbs/util/rbs_assert.h +12 -1
  96. data/include/rbs/util/rbs_encoding.h +2 -0
  97. data/include/rbs/util/rbs_unescape.h +2 -1
  98. data/lib/rbs/ast/annotation.rb +1 -1
  99. data/lib/rbs/ast/comment.rb +1 -1
  100. data/lib/rbs/ast/declarations.rb +10 -10
  101. data/lib/rbs/ast/members.rb +14 -14
  102. data/lib/rbs/ast/ruby/annotations.rb +137 -0
  103. data/lib/rbs/ast/ruby/comment_block.rb +24 -0
  104. data/lib/rbs/ast/ruby/declarations.rb +198 -3
  105. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
  106. data/lib/rbs/ast/ruby/members.rb +159 -1
  107. data/lib/rbs/ast/type_param.rb +24 -4
  108. data/lib/rbs/buffer.rb +20 -15
  109. data/lib/rbs/cli/diff.rb +16 -15
  110. data/lib/rbs/cli/validate.rb +38 -51
  111. data/lib/rbs/cli.rb +52 -19
  112. data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
  113. data/lib/rbs/collection/sources/git.rb +1 -0
  114. data/lib/rbs/definition.rb +1 -1
  115. data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
  116. data/lib/rbs/definition_builder/method_builder.rb +20 -0
  117. data/lib/rbs/definition_builder.rb +91 -2
  118. data/lib/rbs/diff.rb +7 -1
  119. data/lib/rbs/environment.rb +227 -74
  120. data/lib/rbs/environment_loader.rb +0 -6
  121. data/lib/rbs/errors.rb +27 -7
  122. data/lib/rbs/inline_parser.rb +341 -5
  123. data/lib/rbs/location_aux.rb +1 -1
  124. data/lib/rbs/locator.rb +5 -1
  125. data/lib/rbs/method_type.rb +5 -3
  126. data/lib/rbs/parser_aux.rb +2 -2
  127. data/lib/rbs/prototype/rb.rb +2 -2
  128. data/lib/rbs/prototype/rbi.rb +2 -0
  129. data/lib/rbs/prototype/runtime.rb +8 -0
  130. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  131. data/lib/rbs/resolver/type_name_resolver.rb +116 -38
  132. data/lib/rbs/subtractor.rb +3 -1
  133. data/lib/rbs/test/type_check.rb +16 -2
  134. data/lib/rbs/type_name.rb +1 -1
  135. data/lib/rbs/types.rb +27 -27
  136. data/lib/rbs/validator.rb +2 -2
  137. data/lib/rbs/version.rb +1 -1
  138. data/lib/rbs.rb +1 -1
  139. data/lib/rdoc/discover.rb +1 -1
  140. data/lib/rdoc_plugin/parser.rb +1 -1
  141. data/rbs.gemspec +3 -2
  142. data/schema/typeParam.json +17 -1
  143. data/sig/ast/ruby/annotations.rbs +124 -0
  144. data/sig/ast/ruby/comment_block.rbs +8 -0
  145. data/sig/ast/ruby/declarations.rbs +102 -4
  146. data/sig/ast/ruby/members.rbs +87 -1
  147. data/sig/cli/diff.rbs +5 -11
  148. data/sig/cli/validate.rbs +13 -4
  149. data/sig/cli.rbs +18 -18
  150. data/sig/definition.rbs +6 -1
  151. data/sig/environment.rbs +70 -12
  152. data/sig/errors.rbs +13 -6
  153. data/sig/inline_parser.rbs +39 -2
  154. data/sig/locator.rbs +0 -2
  155. data/sig/manifest.yaml +0 -1
  156. data/sig/method_builder.rbs +3 -1
  157. data/sig/method_types.rbs +1 -1
  158. data/sig/parser.rbs +16 -2
  159. data/sig/resolver/type_name_resolver.rbs +35 -7
  160. data/sig/source.rbs +3 -3
  161. data/sig/type_param.rbs +13 -8
  162. data/sig/types.rbs +4 -4
  163. data/src/ast.c +80 -1
  164. data/src/lexer.c +1392 -1313
  165. data/src/lexer.re +3 -0
  166. data/src/lexstate.c +58 -37
  167. data/src/location.c +4 -4
  168. data/src/parser.c +412 -145
  169. data/src/string.c +0 -48
  170. data/src/util/rbs_allocator.c +89 -71
  171. data/src/util/rbs_assert.c +1 -1
  172. data/src/util/rbs_buffer.c +2 -2
  173. data/src/util/rbs_constant_pool.c +10 -10
  174. data/src/util/rbs_encoding.c +4 -8
  175. data/src/util/rbs_unescape.c +56 -20
  176. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  177. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  178. data/stdlib/cgi/0/core.rbs +9 -393
  179. data/stdlib/cgi/0/manifest.yaml +1 -0
  180. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  181. data/stdlib/coverage/0/coverage.rbs +3 -1
  182. data/stdlib/date/0/date.rbs +67 -59
  183. data/stdlib/date/0/date_time.rbs +1 -1
  184. data/stdlib/delegate/0/delegator.rbs +10 -7
  185. data/stdlib/digest/0/digest.rbs +110 -0
  186. data/stdlib/erb/0/erb.rbs +737 -347
  187. data/stdlib/fileutils/0/fileutils.rbs +20 -14
  188. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  189. data/stdlib/json/0/json.rbs +82 -28
  190. data/stdlib/net-http/0/net-http.rbs +3 -0
  191. data/stdlib/objspace/0/objspace.rbs +9 -27
  192. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  193. data/stdlib/open3/0/open3.rbs +459 -1
  194. data/stdlib/openssl/0/openssl.rbs +331 -228
  195. data/stdlib/optparse/0/optparse.rbs +8 -3
  196. data/stdlib/pathname/0/pathname.rbs +9 -1379
  197. data/stdlib/psych/0/psych.rbs +4 -4
  198. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  199. data/stdlib/rdoc/0/code_object.rbs +2 -1
  200. data/stdlib/rdoc/0/parser.rbs +1 -1
  201. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  202. data/stdlib/rdoc/0/store.rbs +1 -1
  203. data/stdlib/resolv/0/resolv.rbs +25 -68
  204. data/stdlib/ripper/0/ripper.rbs +2 -2
  205. data/stdlib/securerandom/0/manifest.yaml +2 -0
  206. data/stdlib/securerandom/0/securerandom.rbs +6 -19
  207. data/stdlib/singleton/0/singleton.rbs +3 -0
  208. data/stdlib/socket/0/socket.rbs +13 -1
  209. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  210. data/stdlib/stringio/0/stringio.rbs +1176 -85
  211. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  212. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  213. data/stdlib/time/0/time.rbs +1 -1
  214. data/stdlib/timeout/0/timeout.rbs +63 -7
  215. data/stdlib/tsort/0/cyclic.rbs +3 -0
  216. data/stdlib/uri/0/common.rbs +16 -2
  217. data/stdlib/uri/0/file.rbs +1 -1
  218. data/stdlib/uri/0/generic.rbs +24 -16
  219. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  220. data/stdlib/zlib/0/gzip_reader.rbs +2 -2
  221. data/stdlib/zlib/0/gzip_writer.rbs +1 -1
  222. data/stdlib/zlib/0/zstream.rbs +1 -0
  223. metadata +30 -4
data/core/random.rbs CHANGED
@@ -96,6 +96,23 @@ class Random < RBS::Unnamed::Random_Base
96
96
  | (Float | ::Range[Float] max) -> Float
97
97
  | [T < Numeric] (::Range[T]) -> T
98
98
 
99
+ # <!--
100
+ # rdoc-file=random.c
101
+ # - Random.seed -> integer
102
+ # -->
103
+ # Returns the seed value used to initialize the Ruby system PRNG. This may be
104
+ # used to initialize another generator with the same state at a later time,
105
+ # causing it to produce the same sequence of numbers.
106
+ #
107
+ # Random.seed #=> 1234
108
+ # prng1 = Random.new(Random.seed)
109
+ # prng1.seed #=> 1234
110
+ # prng1.rand(100) #=> 47
111
+ # Random.seed #=> 1234
112
+ # Random.rand(100) #=> 47
113
+ #
114
+ def self.seed: () -> ::Integer
115
+
99
116
  # <!--
100
117
  # rdoc-file=random.c
101
118
  # - srand(number = Random.new_seed) -> old_seed
data/core/range.rbs CHANGED
@@ -86,14 +86,14 @@
86
86
  # end
87
87
  # a # => [2, 4, 6, 8, 10]
88
88
  #
89
- # A range can be both beginless and endless. For literal beginless, endless
89
+ # A range can be both beginless and endless. For literal beginless, endless
90
90
  # ranges, at least the beginning or end of the range must be given as an
91
91
  # explicit nil value. It is recommended to use an explicit nil beginning and
92
- # implicit nil end, since that is what Ruby uses for Range#inspect:
92
+ # end, since that is what Ruby uses for Range#inspect:
93
93
  #
94
- # (nil..) # => (nil..)
95
- # (..nil) # => (nil..)
96
- # (nil..nil) # => (nil..)
94
+ # (nil..) # => (nil..nil)
95
+ # (..nil) # => (nil..nil)
96
+ # (nil..nil) # => (nil..nil)
97
97
  #
98
98
  # ## Ranges and Other Classes
99
99
  #
@@ -351,7 +351,7 @@ class Range[out Elem] < Object
351
351
  # -->
352
352
  # Returns an element from `self` selected by a binary search.
353
353
  #
354
- # See [Binary Searching](rdoc-ref:bsearch.rdoc).
354
+ # See [Binary Searching](rdoc-ref:language/bsearch.rdoc).
355
355
  #
356
356
  def bsearch: () -> ::Enumerator[Elem, Elem?]
357
357
  | () { (Elem) -> (true | false) } -> Elem?
@@ -741,10 +741,7 @@ class Range[out Elem] < Object
741
741
  #
742
742
  # Related: Range#min, Range#minmax.
743
743
  #
744
- def max: () -> Elem
745
- | () { (Elem a, Elem b) -> Integer } -> Elem
746
- | (Integer n) -> ::Array[Elem]
747
- | (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
744
+ def max: ...
748
745
 
749
746
  # <!--
750
747
  # rdoc-file=range.c
@@ -826,10 +823,52 @@ class Range[out Elem] < Object
826
823
  #
827
824
  # Related: Range#max, Range#minmax.
828
825
  #
829
- def min: () -> Elem
830
- | () { (Elem a, Elem b) -> Integer } -> Elem
831
- | (Integer n) -> ::Array[Elem]
832
- | (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
826
+ def min: ...
827
+
828
+ # <!--
829
+ # rdoc-file=range.c
830
+ # - minmax -> [object, object]
831
+ # - minmax {|a, b| ... } -> [object, object]
832
+ # -->
833
+ # Returns a 2-element array containing the minimum and maximum value in `self`,
834
+ # either according to comparison method `#<=>` or a given block.
835
+ #
836
+ # With no block given, returns the minimum and maximum values, using `#<=>` for
837
+ # comparison:
838
+ #
839
+ # (1..4).minmax # => [1, 4]
840
+ # (1...4).minmax # => [1, 3]
841
+ # ('a'..'d').minmax # => ["a", "d"]
842
+ # (-4..-1).minmax # => [-4, -1]
843
+ #
844
+ # With a block given, the block must return an integer:
845
+ #
846
+ # * Negative if `a` is smaller than `b`.
847
+ # * Zero if `a` and `b` are equal.
848
+ # * Positive if `a` is larger than `b`.
849
+ #
850
+ # The block is called `self.size` times to compare elements; returns a 2-element
851
+ # Array containing the minimum and maximum values from `self`, per the block:
852
+ #
853
+ # (1..4).minmax {|a, b| -(a <=> b) } # => [4, 1]
854
+ #
855
+ # Returns `[nil, nil]` if:
856
+ #
857
+ # * The begin value of the range is larger than the end value:
858
+ #
859
+ # (4..1).minmax # => [nil, nil]
860
+ # (4..1).minmax {|a, b| -(a <=> b) } # => [nil, nil]
861
+ #
862
+ # * The begin value of an exclusive range is equal to the end value:
863
+ #
864
+ # (1...1).minmax # => [nil, nil]
865
+ # (1...1).minmax {|a, b| -(a <=> b) } # => [nil, nil]
866
+ #
867
+ # Raises an exception if `self` is a beginless or an endless range.
868
+ #
869
+ # Related: Range#min, Range#max.
870
+ #
871
+ def minmax: ...
833
872
 
834
873
  # <!--
835
874
  # rdoc-file=range.c
@@ -936,8 +975,43 @@ class Range[out Elem] < Object
936
975
  #
937
976
  # Related: Range#count.
938
977
  #
939
- def size: () -> Integer?
940
- | () -> Float?
978
+ def size: () -> (Integer | Float | nil)
979
+
980
+ # <!--
981
+ # rdoc-file=range.c
982
+ # - count -> integer
983
+ # - count(object) -> integer
984
+ # - count {|element| ... } -> integer
985
+ # -->
986
+ # Returns the count of elements, based on an argument or block criterion, if
987
+ # given.
988
+ #
989
+ # With no argument and no block given, returns the number of elements:
990
+ #
991
+ # (1..4).count # => 4
992
+ # (1...4).count # => 3
993
+ # ('a'..'d').count # => 4
994
+ # ('a'...'d').count # => 3
995
+ # (1..).count # => Infinity
996
+ # (..4).count # => Infinity
997
+ #
998
+ # With argument `object`, returns the number of `object` found in `self`, which
999
+ # will usually be zero or one:
1000
+ #
1001
+ # (1..4).count(2) # => 1
1002
+ # (1..4).count(5) # => 0
1003
+ # (1..4).count('a') # => 0
1004
+ #
1005
+ # With a block given, calls the block with each element; returns the number of
1006
+ # elements for which the block returns a truthy value:
1007
+ #
1008
+ # (1..4).count {|element| element < 3 } # => 2
1009
+ #
1010
+ # Related: Range#size.
1011
+ #
1012
+ def count: () -> (Integer | Float)
1013
+ | (untyped) -> Integer
1014
+ | () { (Elem) -> boolish } -> Integer
941
1015
 
942
1016
  # <!--
943
1017
  # rdoc-file=range.c
@@ -1104,4 +1178,27 @@ class Range[out Elem] < Object
1104
1178
  # Related: Range#cover?.
1105
1179
  #
1106
1180
  def member?: (untyped obj) -> bool
1181
+
1182
+ # <!--
1183
+ # rdoc-file=range.c
1184
+ # - to_a -> array
1185
+ # -->
1186
+ # Returns an array containing the elements in `self`, if a finite collection;
1187
+ # raises an exception otherwise.
1188
+ #
1189
+ # (1..4).to_a # => [1, 2, 3, 4]
1190
+ # (1...4).to_a # => [1, 2, 3]
1191
+ # ('a'..'d').to_a # => ["a", "b", "c", "d"]
1192
+ #
1193
+ def to_a: ...
1194
+
1195
+ # <!-- rdoc-file=range.c -->
1196
+ # Returns an array containing the elements in `self`, if a finite collection;
1197
+ # raises an exception otherwise.
1198
+ #
1199
+ # (1..4).to_a # => [1, 2, 3, 4]
1200
+ # (1...4).to_a # => [1, 2, 3]
1201
+ # ('a'..'d').to_a # => ["a", "b", "c", "d"]
1202
+ #
1203
+ alias entries to_a
1107
1204
  end
data/core/rational.rbs CHANGED
@@ -53,15 +53,16 @@ class Rational < Numeric
53
53
 
54
54
  # <!--
55
55
  # rdoc-file=rational.c
56
- # - rat * numeric -> numeric
56
+ # - self * other -> numeric
57
57
  # -->
58
- # Performs multiplication.
58
+ # Returns the numeric product of `self` and `other`:
59
59
  #
60
- # Rational(2, 3) * Rational(2, 3) #=> (4/9)
61
- # Rational(900) * Rational(1) #=> (900/1)
62
- # Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
63
- # Rational(9, 8) * 4 #=> (9/2)
64
- # Rational(20, 9) * 9.8 #=> 21.77777777777778
60
+ # Rational(9, 8) * 4 #=> (9/2)
61
+ # Rational(20, 9) * 9.8 #=> 21.77777777777778
62
+ # Rational(9, 8) * Complex(1, 2) # => ((9/8)+(9/4)*i)
63
+ # Rational(2, 3) * Rational(2, 3) #=> (4/9)
64
+ # Rational(900) * Rational(1) #=> (900/1)
65
+ # Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
65
66
  #
66
67
  def *: (Integer) -> Rational
67
68
  | (Rational) -> Rational
@@ -69,9 +70,9 @@ class Rational < Numeric
69
70
 
70
71
  # <!--
71
72
  # rdoc-file=rational.c
72
- # - rat ** numeric -> numeric
73
+ # - self ** exponent -> numeric
73
74
  # -->
74
- # Performs exponentiation.
75
+ # Returns `self` raised to the power `exponent`:
75
76
  #
76
77
  # Rational(2) ** Rational(3) #=> (8/1)
77
78
  # Rational(10) ** -2 #=> (1/100)
@@ -85,27 +86,35 @@ class Rational < Numeric
85
86
 
86
87
  # <!--
87
88
  # rdoc-file=rational.c
88
- # - rat + numeric -> numeric
89
+ # - self + other -> numeric
89
90
  # -->
90
- # Performs addition.
91
+ # Returns the sum of `self` and `other`:
91
92
  #
92
- # Rational(2, 3) + Rational(2, 3) #=> (4/3)
93
- # Rational(900) + Rational(1) #=> (901/1)
94
- # Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
95
- # Rational(9, 8) + 4 #=> (41/8)
96
- # Rational(20, 9) + 9.8 #=> 12.022222222222222
93
+ # Rational(2, 3) + 0 # => (2/3)
94
+ # Rational(2, 3) + 1 # => (5/3)
95
+ # Rational(2, 3) + -1 # => (-1/3)
96
+ #
97
+ # Rational(2, 3) + Complex(1, 0) # => ((5/3)+0i)
98
+ #
99
+ # Rational(2, 3) + Rational(1, 1) # => (5/3)
100
+ # Rational(2, 3) + Rational(3, 2) # => (13/6)
101
+ # Rational(2, 3) + Rational(3.0, 2.0) # => (13/6)
102
+ # Rational(2, 3) + Rational(3.1, 2.1) # => (30399297484750849/14186338826217063)
103
+ #
104
+ # For a computation involving Floats, the result may be inexact (see Float#+):
105
+ #
106
+ # Rational(2, 3) + 1.0 # => 1.6666666666666665
107
+ # Rational(2, 3) + Complex(1.0, 0.0) # => (1.6666666666666665+0.0i)
97
108
  #
98
109
  def +: (Float) -> Float
99
110
  | (Complex) -> Complex
100
111
  | (Numeric) -> Rational
101
112
 
102
- def +@: () -> Rational
103
-
104
113
  # <!--
105
114
  # rdoc-file=rational.c
106
- # - rat - numeric -> numeric
115
+ # - self - other -> numeric
107
116
  # -->
108
- # Performs subtraction.
117
+ # Returns the difference of `self` and `other`:
109
118
  #
110
119
  # Rational(2, 3) - Rational(2, 3) #=> (0/1)
111
120
  # Rational(900) - Rational(1) #=> (899/1)
@@ -119,18 +128,20 @@ class Rational < Numeric
119
128
 
120
129
  # <!--
121
130
  # rdoc-file=rational.c
122
- # - -rat -> rational
131
+ # - -self -> rational
123
132
  # -->
124
- # Negates `rat`.
133
+ # Returns `self`, negated:
134
+ #
135
+ # -(1/3r) # => (-1/3)
136
+ # -(-1/3r) # => (1/3)
125
137
  #
126
138
  def -@: () -> Rational
127
139
 
128
140
  # <!--
129
141
  # rdoc-file=rational.c
130
- # - rat / numeric -> numeric
131
- # - rat.quo(numeric) -> numeric
142
+ # - self / other -> numeric
132
143
  # -->
133
- # Performs division.
144
+ # Returns the quotient of `self` and `other`:
134
145
  #
135
146
  # Rational(2, 3) / Rational(2, 3) #=> (1/1)
136
147
  # Rational(900) / Rational(1) #=> (900/1)
@@ -144,20 +155,29 @@ class Rational < Numeric
144
155
 
145
156
  # <!--
146
157
  # rdoc-file=rational.c
147
- # - rational <=> numeric -> -1, 0, +1, or nil
158
+ # - self <=> other -> -1, 0, 1, or nil
148
159
  # -->
149
- # Returns -1, 0, or +1 depending on whether `rational` is less than, equal to,
150
- # or greater than `numeric`.
160
+ # Compares `self` and `other`.
161
+ #
162
+ # Returns:
163
+ #
164
+ # * `-1`, if `self` is less than `other`.
165
+ # * `0`, if the two values are the same.
166
+ # * `1`, if `self` is greater than `other`.
167
+ # * `nil`, if the two values are incomparable.
151
168
  #
152
- # `nil` is returned if the two values are incomparable.
169
+ # Examples:
153
170
  #
154
- # Rational(2, 3) <=> Rational(2, 3) #=> 0
155
- # Rational(5) <=> 5 #=> 0
156
- # Rational(2, 3) <=> Rational(1, 3) #=> 1
157
- # Rational(1, 3) <=> 1 #=> -1
158
- # Rational(1, 3) <=> 0.3 #=> 1
171
+ # Rational(2, 3) <=> Rational(4, 3) # => -1
172
+ # Rational(2, 1) <=> Rational(2, 1) # => 0
173
+ # Rational(2, 1) <=> 2 # => 0
174
+ # Rational(2, 1) <=> 2.0 # => 0
175
+ # Rational(2, 1) <=> Complex(2, 0) # => 0
176
+ # Rational(4, 3) <=> Rational(2, 3) # => 1
177
+ # Rational(4, 3) <=> :foo # => nil
159
178
  #
160
- # Rational(1, 3) <=> "0.3" #=> nil
179
+ # Class Rational includes module Comparable, each of whose methods uses
180
+ # Rational#<=> for comparison.
161
181
  #
162
182
  def <=>: (Integer | Rational) -> Integer
163
183
  | (untyped) -> Integer?
@@ -188,12 +208,6 @@ class Rational < Numeric
188
208
  #
189
209
  def abs: () -> Rational
190
210
 
191
- def abs2: () -> Rational
192
-
193
- def angle: () -> (Integer | Float)
194
-
195
- alias arg angle
196
-
197
211
  # <!--
198
212
  # rdoc-file=rational.c
199
213
  # - rat.ceil([ndigits]) -> integer or rational
@@ -222,10 +236,6 @@ class Rational < Numeric
222
236
 
223
237
  def coerce: (Numeric) -> [ Numeric, Numeric ]
224
238
 
225
- def conj: () -> Rational
226
-
227
- def conjugate: () -> Rational
228
-
229
239
  # <!--
230
240
  # rdoc-file=rational.c
231
241
  # - rat.denominator -> integer
@@ -239,15 +249,9 @@ class Rational < Numeric
239
249
  #
240
250
  def denominator: () -> Integer
241
251
 
242
- def div: (Numeric) -> Integer
243
-
244
252
  def divmod: (Integer | Float | Rational) -> [ Integer, Rational ]
245
253
  | (Numeric) -> [ Numeric, Numeric ]
246
254
 
247
- def dup: () -> self
248
-
249
- def eql?: (untyped) -> bool
250
-
251
255
  # <!--
252
256
  # rdoc-file=rational.c
253
257
  # - rat.fdiv(numeric) -> float
@@ -260,8 +264,6 @@ class Rational < Numeric
260
264
  #
261
265
  def fdiv: (Numeric) -> Float
262
266
 
263
- def finite?: () -> bool
264
-
265
267
  # <!--
266
268
  # rdoc-file=rational.c
267
269
  # - rat.floor([ndigits]) -> integer or rational
@@ -295,14 +297,6 @@ class Rational < Numeric
295
297
  #
296
298
  def hash: () -> Integer
297
299
 
298
- def i: () -> Complex
299
-
300
- def imag: () -> Integer
301
-
302
- def imaginary: () -> Integer
303
-
304
- def infinite?: () -> Integer?
305
-
306
300
  # <!--
307
301
  # rdoc-file=rational.c
308
302
  # - rat.inspect -> string
@@ -315,8 +309,6 @@ class Rational < Numeric
315
309
  #
316
310
  def inspect: () -> String
317
311
 
318
- def integer?: () -> bool
319
-
320
312
  # <!-- rdoc-file=rational.c -->
321
313
  # Returns the absolute value of `rat`.
322
314
  #
@@ -336,8 +328,6 @@ class Rational < Numeric
336
328
  #
337
329
  def negative?: () -> bool
338
330
 
339
- def nonzero?: () -> self?
340
-
341
331
  # <!--
342
332
  # rdoc-file=rational.c
343
333
  # - rat.numerator -> integer
@@ -351,8 +341,6 @@ class Rational < Numeric
351
341
  #
352
342
  def numerator: () -> Integer
353
343
 
354
- alias phase angle
355
-
356
344
  def polar: () -> [ Rational, Integer | Float ]
357
345
 
358
346
  # <!--
@@ -364,7 +352,7 @@ class Rational < Numeric
364
352
  def positive?: () -> bool
365
353
 
366
354
  # <!-- rdoc-file=rational.c -->
367
- # Performs division.
355
+ # Returns the quotient of `self` and `other`:
368
356
  #
369
357
  # Rational(2, 3) / Rational(2, 3) #=> (1/1)
370
358
  # Rational(900) / Rational(1) #=> (900/1)
@@ -391,14 +379,8 @@ class Rational < Numeric
391
379
  #
392
380
  def rationalize: (?Numeric eps) -> Rational
393
381
 
394
- def real: () -> Rational
395
-
396
- def real?: () -> true
397
-
398
382
  def rect: () -> [ Rational, Numeric ]
399
383
 
400
- alias rectangular rect
401
-
402
384
  def remainder: (Float) -> Float
403
385
  | (Numeric) -> Rational
404
386
 
@@ -440,13 +422,6 @@ class Rational < Numeric
440
422
  def round: (?half: :up | :down | :even) -> Integer
441
423
  | (Integer digits, ?half: :up | :down | :even) -> (Integer | Rational)
442
424
 
443
- def step: (?Numeric limit, ?Numeric step) { (Rational) -> void } -> self
444
- | (?Numeric limit, ?Numeric step) -> Enumerator[Rational, self]
445
- | (?by: Numeric, ?to: Numeric) { (Rational) -> void } -> self
446
- | (?by: Numeric, ?to: Numeric) -> Enumerator[Rational, self]
447
-
448
- def to_c: () -> Complex
449
-
450
425
  # <!--
451
426
  # rdoc-file=rational.c
452
427
  # - rat.to_f -> float
@@ -476,8 +451,6 @@ class Rational < Numeric
476
451
  #
477
452
  def to_i: () -> Integer
478
453
 
479
- alias to_int to_i
480
-
481
454
  # <!--
482
455
  # rdoc-file=rational.c
483
456
  # - rat.to_r -> self
@@ -526,6 +499,4 @@ class Rational < Numeric
526
499
  #
527
500
  def truncate: () -> Integer
528
501
  | (Integer ndigits) -> (Integer | Rational)
529
-
530
- def zero?: () -> bool
531
502
  end
@@ -93,7 +93,7 @@ module RBS
93
93
  # * File `t.rb`:
94
94
  #
95
95
  # p "ARGV: #{ARGV}"
96
- # p "Line: #{ARGF.read}" # Read everything from all specified streams.
96
+ # p "Read: #{ARGF.read}" # Read everything from all specified streams.
97
97
  #
98
98
  # * Command and output:
99
99
  #
@@ -836,7 +836,7 @@ module RBS
836
836
  # Formats and writes `objects` to the stream.
837
837
  #
838
838
  # For details on `format_string`, see [Format
839
- # Specifications](rdoc-ref:format_specifications.rdoc).
839
+ # Specifications](rdoc-ref:language/format_specifications.rdoc).
840
840
  #
841
841
  %a{annotate:rdoc:copy:ARGF#printf}
842
842
  def printf: (String format_string, *untyped args) -> nil
@@ -140,7 +140,7 @@ module RBS
140
140
  #
141
141
  # * ::assoc: Returns a 2-element array containing the name and value of the
142
142
  # named environment variable if it exists:
143
- # * ::clone: Returns `ENV` (and issues a warning).
143
+ # * ::clone: Raises an exception.
144
144
  # * ::except: Returns a hash of all name/value pairs except those given.
145
145
  # * ::fetch: Returns the value for the given name.
146
146
  # * ::inspect: Returns the contents of `ENV` as a string.
@@ -31,9 +31,11 @@ module RBS
31
31
  # prng.rand(100) # => 42
32
32
  #
33
33
  # When `max` is a Float, `rand` returns a random floating point number between
34
- # 0.0 and `max`, including 0.0 and excluding `max`.
34
+ # 0.0 and `max`, including 0.0 and excluding `max`. Note that it behaves
35
+ # differently from Kernel.rand.
35
36
  #
36
- # prng.rand(1.5) # => 1.4600282860034115
37
+ # prng.rand(1.5) # => 1.4600282860034115
38
+ # rand(1.5) # => 0
37
39
  #
38
40
  # When `range` is a Range, `rand` returns a random number where
39
41
  # `range.member?(number) == true`.
@@ -146,56 +148,6 @@ module RBS
146
148
  #
147
149
  %a{annotate:rdoc:copy:Random::Formatter}
148
150
  module Random_Formatter
149
- # <!--
150
- # rdoc-file=lib/random/formatter.rb
151
- # - base64(n=nil)
152
- # -->
153
- # Generate a random base64 string.
154
- #
155
- # The argument *n* specifies the length, in bytes, of the random number to be
156
- # generated. The length of the result string is about 4/3 of *n*.
157
- #
158
- # If *n* is not specified or is nil, 16 is assumed. It may be larger in the
159
- # future.
160
- #
161
- # The result may contain A-Z, a-z, 0-9, "+", "/" and "=".
162
- #
163
- # require 'random/formatter'
164
- #
165
- # Random.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="
166
- # # or
167
- # prng = Random.new
168
- # prng.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="
169
- #
170
- # See RFC 3548 for the definition of base64.
171
- #
172
- %a{annotate:rdoc:copy:Random::Formatter#base64}
173
- def base64: (?Integer? n) -> String
174
-
175
- # <!--
176
- # rdoc-file=lib/random/formatter.rb
177
- # - hex(n=nil)
178
- # -->
179
- # Generate a random hexadecimal string.
180
- #
181
- # The argument *n* specifies the length, in bytes, of the random number to be
182
- # generated. The length of the resulting hexadecimal string is twice of *n*.
183
- #
184
- # If *n* is not specified or is nil, 16 is assumed. It may be larger in the
185
- # future.
186
- #
187
- # The result may contain 0-9 and a-f.
188
- #
189
- # require 'random/formatter'
190
- #
191
- # Random.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
192
- # # or
193
- # prng = Random.new
194
- # prng.hex #=> "91dc3bfb4de5b11d029d376634589b61"
195
- #
196
- %a{annotate:rdoc:copy:Random::Formatter#hex}
197
- def hex: (?Integer? n) -> String
198
-
199
151
  # <!-- rdoc-file=random.c -->
200
152
  # Generates formatted random number from raw random bytes. See Random#rand.
201
153
  #
@@ -208,9 +160,6 @@ module RBS
208
160
  | (::Range[Integer] n) -> Integer
209
161
  | (::Range[Numeric] n) -> Numeric
210
162
 
211
- %a{annotate:rdoc:copy:Random::Formatter#random_byte}
212
- def random_bytes: (?Integer? n) -> String
213
-
214
163
  # <!--
215
164
  # rdoc-file=random.c
216
165
  # - prng.random_number -> float
@@ -230,64 +179,6 @@ module RBS
230
179
  | (?::Range[Float]? n) -> Float
231
180
  | (?::Range[Integer]? n) -> Integer
232
181
  | (?::Range[Numeric]? n) -> Numeric
233
-
234
- # <!--
235
- # rdoc-file=lib/random/formatter.rb
236
- # - urlsafe_base64(n=nil, padding=false)
237
- # -->
238
- # Generate a random URL-safe base64 string.
239
- #
240
- # The argument *n* specifies the length, in bytes, of the random number to be
241
- # generated. The length of the result string is about 4/3 of *n*.
242
- #
243
- # If *n* is not specified or is nil, 16 is assumed. It may be larger in the
244
- # future.
245
- #
246
- # The boolean argument *padding* specifies the padding. If it is false or nil,
247
- # padding is not generated. Otherwise padding is generated. By default, padding
248
- # is not generated because "=" may be used as a URL delimiter.
249
- #
250
- # The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also used if
251
- # *padding* is true.
252
- #
253
- # require 'random/formatter'
254
- #
255
- # Random.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
256
- # # or
257
- # prng = Random.new
258
- # prng.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
259
- #
260
- # prng.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
261
- # prng.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
262
- #
263
- # See RFC 3548 for the definition of URL-safe base64.
264
- #
265
- %a{annotate:rdoc:copy:Random::Formatter#urlsafe_base64}
266
- def urlsafe_base64: (?Integer? n, ?boolish padding) -> String
267
-
268
- # <!--
269
- # rdoc-file=lib/random/formatter.rb
270
- # - uuid()
271
- # -->
272
- # Generate a random v4 UUID (Universally Unique IDentifier).
273
- #
274
- # require 'random/formatter'
275
- #
276
- # Random.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
277
- # Random.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
278
- # # or
279
- # prng = Random.new
280
- # prng.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
281
- #
282
- # The version 4 UUID is purely random (except the version). It doesn't contain
283
- # meaningful information such as MAC addresses, timestamps, etc.
284
- #
285
- # The result contains 122 random bits (15.25 random bytes).
286
- #
287
- # See [RFC9562](https://www.rfc-editor.org/rfc/rfc9562) for details of UUIDv4.
288
- #
289
- %a{annotate:rdoc:copy:Random::Formatter#uuid}
290
- def uuid: () -> String
291
182
  end
292
183
  end
293
184
  end