rbs 3.9.5 → 3.10.0

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 (189) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +74 -0
  3. data/.clangd +2 -0
  4. data/.github/workflows/c-check.yml +54 -0
  5. data/.github/workflows/comments.yml +3 -3
  6. data/.github/workflows/ruby.yml +34 -19
  7. data/.github/workflows/typecheck.yml +1 -1
  8. data/.github/workflows/windows.yml +1 -1
  9. data/.gitignore +4 -0
  10. data/CHANGELOG.md +49 -0
  11. data/README.md +38 -1
  12. data/Rakefile +152 -23
  13. data/config.yml +190 -62
  14. data/core/array.rbs +100 -46
  15. data/core/complex.rbs +32 -21
  16. data/core/dir.rbs +2 -2
  17. data/core/encoding.rbs +6 -9
  18. data/core/enumerable.rbs +90 -3
  19. data/core/enumerator.rbs +18 -1
  20. data/core/errno.rbs +8 -0
  21. data/core/errors.rbs +28 -1
  22. data/core/exception.rbs +2 -2
  23. data/core/fiber.rbs +5 -4
  24. data/core/file.rbs +27 -12
  25. data/core/file_test.rbs +1 -1
  26. data/core/float.rbs +209 -22
  27. data/core/gc.rbs +417 -281
  28. data/core/hash.rbs +1024 -727
  29. data/core/integer.rbs +78 -38
  30. data/core/io/buffer.rbs +18 -7
  31. data/core/io/wait.rbs +11 -33
  32. data/core/io.rbs +14 -12
  33. data/core/kernel.rbs +57 -51
  34. data/core/marshal.rbs +1 -1
  35. data/core/match_data.rbs +1 -1
  36. data/core/math.rbs +42 -3
  37. data/core/method.rbs +14 -6
  38. data/core/module.rbs +88 -17
  39. data/core/nil_class.rbs +3 -3
  40. data/core/numeric.rbs +16 -16
  41. data/core/object.rbs +3 -3
  42. data/core/object_space.rbs +21 -15
  43. data/{stdlib/pathname/0 → core}/pathname.rbs +255 -355
  44. data/core/proc.rbs +15 -8
  45. data/core/process.rbs +2 -2
  46. data/core/ractor.rbs +278 -437
  47. data/core/range.rbs +7 -8
  48. data/core/rational.rbs +37 -24
  49. data/core/rbs/unnamed/argf.rbs +2 -2
  50. data/core/rbs/unnamed/env_class.rbs +1 -1
  51. data/core/rbs/unnamed/random.rbs +4 -2
  52. data/core/regexp.rbs +25 -20
  53. data/core/ruby.rbs +53 -0
  54. data/core/ruby_vm.rbs +6 -4
  55. data/core/rubygems/errors.rbs +3 -70
  56. data/core/rubygems/rubygems.rbs +11 -79
  57. data/core/rubygems/version.rbs +2 -3
  58. data/core/set.rbs +488 -359
  59. data/core/string.rbs +3145 -1231
  60. data/core/struct.rbs +1 -1
  61. data/core/symbol.rbs +4 -4
  62. data/core/thread.rbs +92 -29
  63. data/core/time.rbs +35 -9
  64. data/core/trace_point.rbs +7 -4
  65. data/core/unbound_method.rbs +14 -6
  66. data/docs/aliases.md +79 -0
  67. data/docs/collection.md +2 -2
  68. data/docs/encoding.md +56 -0
  69. data/docs/gem.md +0 -1
  70. data/docs/sigs.md +3 -3
  71. data/ext/rbs_extension/ast_translation.c +1016 -0
  72. data/ext/rbs_extension/ast_translation.h +37 -0
  73. data/ext/rbs_extension/class_constants.c +155 -0
  74. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
  75. data/ext/rbs_extension/compat.h +10 -0
  76. data/ext/rbs_extension/extconf.rb +25 -1
  77. data/ext/rbs_extension/legacy_location.c +317 -0
  78. data/ext/rbs_extension/legacy_location.h +45 -0
  79. data/ext/rbs_extension/main.c +357 -14
  80. data/ext/rbs_extension/rbs_extension.h +6 -21
  81. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  82. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  83. data/include/rbs/ast.h +687 -0
  84. data/include/rbs/defines.h +86 -0
  85. data/include/rbs/lexer.h +199 -0
  86. data/include/rbs/location.h +59 -0
  87. data/include/rbs/parser.h +135 -0
  88. data/include/rbs/string.h +47 -0
  89. data/include/rbs/util/rbs_allocator.h +59 -0
  90. data/include/rbs/util/rbs_assert.h +20 -0
  91. data/include/rbs/util/rbs_buffer.h +83 -0
  92. data/include/rbs/util/rbs_constant_pool.h +6 -67
  93. data/include/rbs/util/rbs_encoding.h +282 -0
  94. data/include/rbs/util/rbs_unescape.h +24 -0
  95. data/include/rbs.h +1 -2
  96. data/lib/rbs/annotate/formatter.rb +3 -13
  97. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  98. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  99. data/lib/rbs/cli/validate.rb +2 -2
  100. data/lib/rbs/cli.rb +1 -1
  101. data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
  102. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
  103. data/lib/rbs/environment.rb +64 -59
  104. data/lib/rbs/environment_loader.rb +1 -1
  105. data/lib/rbs/errors.rb +1 -1
  106. data/lib/rbs/parser_aux.rb +5 -0
  107. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  108. data/lib/rbs/resolver/type_name_resolver.rb +124 -38
  109. data/lib/rbs/test/type_check.rb +14 -0
  110. data/lib/rbs/types.rb +3 -1
  111. data/lib/rbs/version.rb +1 -1
  112. data/lib/rbs.rb +1 -1
  113. data/lib/rdoc/discover.rb +1 -1
  114. data/lib/rdoc_plugin/parser.rb +3 -3
  115. data/sig/annotate/formatter.rbs +2 -2
  116. data/sig/annotate/rdoc_annotater.rbs +1 -1
  117. data/sig/environment.rbs +57 -6
  118. data/sig/manifest.yaml +0 -1
  119. data/sig/parser.rbs +20 -0
  120. data/sig/resolver/type_name_resolver.rbs +38 -7
  121. data/sig/types.rbs +4 -1
  122. data/src/ast.c +1256 -0
  123. data/src/lexer.c +2956 -0
  124. data/src/lexer.re +147 -0
  125. data/src/lexstate.c +205 -0
  126. data/src/location.c +71 -0
  127. data/src/parser.c +3507 -0
  128. data/src/string.c +41 -0
  129. data/src/util/rbs_allocator.c +152 -0
  130. data/src/util/rbs_assert.c +19 -0
  131. data/src/util/rbs_buffer.c +54 -0
  132. data/src/util/rbs_constant_pool.c +18 -88
  133. data/src/util/rbs_encoding.c +21308 -0
  134. data/src/util/rbs_unescape.c +167 -0
  135. data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
  136. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  137. data/stdlib/cgi/0/core.rbs +2 -396
  138. data/stdlib/cgi/0/manifest.yaml +1 -0
  139. data/stdlib/cgi-escape/0/escape.rbs +153 -0
  140. data/stdlib/coverage/0/coverage.rbs +3 -1
  141. data/stdlib/date/0/date.rbs +67 -59
  142. data/stdlib/date/0/date_time.rbs +1 -1
  143. data/stdlib/delegate/0/delegator.rbs +10 -7
  144. data/stdlib/erb/0/erb.rbs +737 -347
  145. data/stdlib/fileutils/0/fileutils.rbs +18 -13
  146. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  147. data/stdlib/json/0/json.rbs +68 -48
  148. data/stdlib/net-http/0/net-http.rbs +3 -0
  149. data/stdlib/objspace/0/objspace.rbs +9 -4
  150. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  151. data/stdlib/openssl/0/openssl.rbs +331 -228
  152. data/stdlib/optparse/0/optparse.rbs +3 -3
  153. data/stdlib/psych/0/psych.rbs +3 -3
  154. data/stdlib/rdoc/0/code_object.rbs +2 -2
  155. data/stdlib/rdoc/0/comment.rbs +2 -0
  156. data/stdlib/rdoc/0/options.rbs +76 -0
  157. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  158. data/stdlib/rdoc/0/store.rbs +1 -1
  159. data/stdlib/resolv/0/resolv.rbs +25 -68
  160. data/stdlib/ripper/0/ripper.rbs +5 -2
  161. data/stdlib/singleton/0/singleton.rbs +3 -0
  162. data/stdlib/socket/0/socket.rbs +13 -1
  163. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  164. data/stdlib/stringio/0/stringio.rbs +1176 -85
  165. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  166. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  167. data/stdlib/time/0/time.rbs +1 -1
  168. data/stdlib/timeout/0/timeout.rbs +63 -7
  169. data/stdlib/tsort/0/cyclic.rbs +3 -0
  170. data/stdlib/uri/0/common.rbs +11 -2
  171. data/stdlib/uri/0/file.rbs +1 -1
  172. data/stdlib/uri/0/generic.rbs +17 -16
  173. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  174. data/stdlib/zlib/0/zstream.rbs +1 -0
  175. metadata +43 -18
  176. data/ext/rbs_extension/lexer.c +0 -2728
  177. data/ext/rbs_extension/lexer.h +0 -179
  178. data/ext/rbs_extension/lexer.re +0 -147
  179. data/ext/rbs_extension/lexstate.c +0 -175
  180. data/ext/rbs_extension/location.c +0 -325
  181. data/ext/rbs_extension/location.h +0 -85
  182. data/ext/rbs_extension/parser.c +0 -2982
  183. data/ext/rbs_extension/parser.h +0 -18
  184. data/ext/rbs_extension/parserstate.c +0 -411
  185. data/ext/rbs_extension/parserstate.h +0 -163
  186. data/ext/rbs_extension/unescape.c +0 -32
  187. data/include/rbs/ruby_objs.h +0 -72
  188. data/src/constants.c +0 -153
  189. data/src/ruby_objs.c +0 -799
@@ -0,0 +1,167 @@
1
+ #include "rbs/util/rbs_unescape.h"
2
+ #include "rbs/util/rbs_encoding.h"
3
+ #include <string.h>
4
+ #include <stdlib.h>
5
+ #include <ctype.h>
6
+
7
+ // Define the escape character mappings
8
+ // TODO: use a switch instead
9
+ static const struct {
10
+ const char *from;
11
+ const char *to;
12
+ } TABLE[] = {
13
+ { "\\a", "\a" },
14
+ { "\\b", "\b" },
15
+ { "\\e", "\033" },
16
+ { "\\f", "\f" },
17
+ { "\\n", "\n" },
18
+ { "\\r", "\r" },
19
+ { "\\s", " " },
20
+ { "\\t", "\t" },
21
+ { "\\v", "\v" },
22
+ { "\\\"", "\"" },
23
+ { "\\'", "'" },
24
+ { "\\\\", "\\" },
25
+ { "\\", "" }
26
+ };
27
+
28
+ // Helper function to convert hex string to integer
29
+ static int hex_to_int(const char *hex, int length) {
30
+ int result = 0;
31
+ for (int i = 0; i < length; i++) {
32
+ result = result * 16 + (isdigit(hex[i]) ? hex[i] - '0' : tolower(hex[i]) - 'a' + 10);
33
+ }
34
+ return result;
35
+ }
36
+
37
+ // Helper function to convert octal string to integer
38
+ static int octal_to_int(const char *octal, int length) {
39
+ int result = 0;
40
+ for (int i = 0; i < length; i++) {
41
+ result = result * 8 + (octal[i] - '0');
42
+ }
43
+ return result;
44
+ }
45
+
46
+ // Fills buf starting at index 'start' with the UTF-8 encoding of 'codepoint'.
47
+ // Returns the number of bytes written, or 0 when the output is not changed.
48
+ //
49
+ size_t rbs_utf8_fill_codepoint(char *buf, size_t start, size_t end, unsigned int codepoint) {
50
+ if (start + 4 > end) {
51
+ return 0;
52
+ }
53
+
54
+ if (codepoint <= 0x7F) {
55
+ buf[start] = codepoint & 0x7F;
56
+ return 1;
57
+ } else if (codepoint <= 0x7FF) {
58
+ buf[start + 0] = 0xC0 | ((codepoint >> 6) & 0x1F);
59
+ buf[start + 1] = 0x80 | (codepoint & 0x3F);
60
+ return 2;
61
+ } else if (codepoint <= 0xFFFF) {
62
+ buf[start + 0] = 0xE0 | ((codepoint >> 12) & 0x0F);
63
+ buf[start + 1] = 0x80 | ((codepoint >> 6) & 0x3F);
64
+ buf[start + 2] = 0x80 | (codepoint & 0x3F);
65
+ return 3;
66
+ } else if (codepoint <= 0x10FFFF) {
67
+ buf[start + 0] = 0xF0 | ((codepoint >> 18) & 0x07);
68
+ buf[start + 1] = 0x80 | ((codepoint >> 12) & 0x3F);
69
+ buf[start + 2] = 0x80 | ((codepoint >> 6) & 0x3F);
70
+ buf[start + 3] = 0x80 | (codepoint & 0x3F);
71
+ return 4;
72
+ } else {
73
+ return 0;
74
+ }
75
+ }
76
+
77
+ rbs_string_t unescape_string(rbs_allocator_t *allocator, const rbs_string_t string, bool is_double_quote, bool is_unicode) {
78
+ if (!string.start) return RBS_STRING_NULL;
79
+
80
+ size_t len = string.end - string.start;
81
+ const char *input = string.start;
82
+
83
+ // The output cannot be longer than the input even after unescaping.
84
+ char *output = rbs_allocator_alloc_many(allocator, len + 1, char);
85
+ if (!output) return RBS_STRING_NULL;
86
+
87
+ size_t i = 0, j = 0;
88
+ while (i < len) {
89
+ if (input[i] == '\\' && i + 1 < len) {
90
+ if (is_double_quote) {
91
+ if (isdigit(input[i + 1])) {
92
+ // Octal escape
93
+ int octal_len = 1;
94
+ while (octal_len < 3 && i + 1 + octal_len < len && isdigit(input[i + 1 + octal_len]))
95
+ octal_len++;
96
+ int value = octal_to_int(input + i + 1, octal_len);
97
+ output[j++] = (char) value;
98
+ i += octal_len + 1;
99
+ } else if (input[i + 1] == 'x' && i + 3 < len) {
100
+ // Hex escape
101
+ int hex_len = isxdigit(input[i + 3]) ? 2 : 1;
102
+ int value = hex_to_int(input + i + 2, hex_len);
103
+ output[j++] = (char) value;
104
+ i += hex_len + 2;
105
+ } else if (input[i + 1] == 'u' && i + 5 < len) {
106
+ // Unicode escape
107
+
108
+ if (is_unicode) {
109
+ // The UTF-8 representation is at most 4 bytes, shorter than the input length.
110
+ int value = hex_to_int(input + i + 2, 4);
111
+ j += rbs_utf8_fill_codepoint(output, j, len + 1, value);
112
+ i += 6;
113
+ } else {
114
+ // Copy the escape sequence as-is
115
+ output[j++] = input[i++];
116
+ output[j++] = input[i++];
117
+ output[j++] = input[i++];
118
+ output[j++] = input[i++];
119
+ output[j++] = input[i++];
120
+ output[j++] = input[i++];
121
+ }
122
+ } else {
123
+ // Other escapes
124
+ int found = 0;
125
+ for (size_t k = 0; k < sizeof(TABLE) / sizeof(TABLE[0]); k++) {
126
+ if (strncmp(input + i, TABLE[k].from, strlen(TABLE[k].from)) == 0) {
127
+ output[j++] = TABLE[k].to[0];
128
+ i += strlen(TABLE[k].from);
129
+ found = 1;
130
+ break;
131
+ }
132
+ }
133
+ if (!found) {
134
+ output[j++] = input[i++];
135
+ }
136
+ }
137
+ } else {
138
+ /* Single quote: only escape ' and \ */
139
+ if (input[i + 1] == '\'' || input[i + 1] == '\\') {
140
+ output[j++] = input[i + 1];
141
+ i += 2;
142
+ } else {
143
+ output[j++] = input[i++];
144
+ }
145
+ }
146
+ } else {
147
+ output[j++] = input[i++];
148
+ }
149
+ }
150
+ output[j] = '\0';
151
+ return rbs_string_new(output, output + j);
152
+ }
153
+
154
+ rbs_string_t rbs_unquote_string(rbs_allocator_t *allocator, rbs_string_t input, const rbs_encoding_t *encoding) {
155
+ unsigned int first_char = input.start[0];
156
+
157
+ const char *new_start = input.start;
158
+ const char *new_end = input.end;
159
+
160
+ if (first_char == '"' || first_char == '\'' || first_char == '`') {
161
+ new_start += 1;
162
+ new_end -= 1;
163
+ }
164
+
165
+ rbs_string_t string = rbs_string_new(new_start, new_end);
166
+ return unescape_string(allocator, string, first_char == '"', encoding == RBS_ENCODING_UTF_8_ENTRY);
167
+ }
@@ -609,7 +609,7 @@ class BigDecimal < Numeric
609
609
  # The quotient q is (a/b).floor, and the modulus is the amount that must be
610
610
  # added to q * b to get a.
611
611
  #
612
- def divmod: (Numeric) -> [ BigDecimal, BigDecimal ]
612
+ def divmod: (Numeric) -> [ Integer, BigDecimal ]
613
613
 
614
614
  # <!--
615
615
  # rdoc-file=ext/bigdecimal/bigdecimal.c
@@ -783,20 +783,6 @@ class BigDecimal < Numeric
783
783
  #
784
784
  def power: (Numeric n, int prec) -> BigDecimal
785
785
 
786
- # <!--
787
- # rdoc-file=ext/bigdecimal/bigdecimal.c
788
- # - precs -> array
789
- # -->
790
- # Returns an Array of two Integer values that represent platform-dependent
791
- # internal storage properties.
792
- #
793
- # This method is deprecated and will be removed in the future. Instead, use
794
- # BigDecimal#n_significant_digits for obtaining the number of significant digits
795
- # in scientific notation, and BigDecimal#precision for obtaining the number of
796
- # digits in decimal notation.
797
- #
798
- def precs: () -> [ Integer, Integer ]
799
-
800
786
  # <!--
801
787
  # rdoc-file=ext/bigdecimal/bigdecimal.c
802
788
  # - quo(value) -> bigdecimal
@@ -1274,33 +1260,35 @@ class Integer
1274
1260
 
1275
1261
  # <!--
1276
1262
  # rdoc-file=numeric.c
1277
- # - self / numeric -> numeric_result
1263
+ # - self / other -> numeric
1278
1264
  # -->
1279
- # Performs division; for integer `numeric`, truncates the result to an integer:
1265
+ # Returns the quotient of `self` and `other`.
1266
+ #
1267
+ # For integer `other`, truncates the result to an integer:
1280
1268
  #
1281
- # 4 / 3 # => 1
1282
- # 4 / -3 # => -2
1283
- # -4 / 3 # => -2
1284
- # -4 / -3 # => 1
1269
+ # 4 / 3 # => 1
1270
+ # 4 / -3 # => -2
1271
+ # -4 / 3 # => -2
1272
+ # -4 / -3 # => 1
1285
1273
  #
1286
- # For other +numeric+, returns non-integer result:
1274
+ # For non-integer `other`, returns a non-integer result:
1287
1275
  #
1288
- # 4 / 3.0 # => 1.3333333333333333
1289
- # 4 / Rational(3, 1) # => (4/3)
1290
- # 4 / Complex(3, 0) # => ((4/3)+0i)
1276
+ # 4 / 3.0 # => 1.3333333333333333
1277
+ # 4 / Rational(3, 1) # => (4/3)
1278
+ # 4 / Complex(3, 0) # => ((4/3)+0i)
1291
1279
  #
1292
1280
  def /: (BigDecimal) -> BigDecimal
1293
1281
  | ...
1294
1282
 
1295
1283
  # <!--
1296
1284
  # rdoc-file=numeric.c
1297
- # - self * numeric -> numeric_result
1285
+ # - self * other -> numeric
1298
1286
  # -->
1299
- # Performs multiplication:
1287
+ # Returns the numeric product of `self` and `other`:
1300
1288
  #
1301
1289
  # 4 * 2 # => 8
1302
- # 4 * -2 # => -8
1303
1290
  # -4 * 2 # => -8
1291
+ # 4 * -2 # => -8
1304
1292
  # 4 * 2.0 # => 8.0
1305
1293
  # 4 * Rational(1, 3) # => (4/3)
1306
1294
  # 4 * Complex(2, 0) # => (8+0i)
@@ -1310,25 +1298,29 @@ class Integer
1310
1298
 
1311
1299
  # <!--
1312
1300
  # rdoc-file=numeric.c
1313
- # - self + numeric -> numeric_result
1301
+ # - self + other -> numeric
1314
1302
  # -->
1315
- # Performs addition:
1303
+ # Returns the sum of `self` and `other`:
1304
+ #
1305
+ # 1 + 1 # => 2
1306
+ # 1 + -1 # => 0
1307
+ # 1 + 0 # => 1
1308
+ # 1 + -2 # => -1
1309
+ # 1 + Complex(1, 0) # => (2+0i)
1310
+ # 1 + Rational(1, 1) # => (2/1)
1316
1311
  #
1317
- # 2 + 2 # => 4
1318
- # -2 + 2 # => 0
1319
- # -2 + -2 # => -4
1320
- # 2 + 2.0 # => 4.0
1321
- # 2 + Rational(2, 1) # => (4/1)
1322
- # 2 + Complex(2, 0) # => (4+0i)
1312
+ # For a computation involving Floats, the result may be inexact (see Float#+):
1313
+ #
1314
+ # 1 + 3.14 # => 4.140000000000001
1323
1315
  #
1324
1316
  def +: (BigDecimal) -> BigDecimal
1325
1317
  | ...
1326
1318
 
1327
1319
  # <!--
1328
1320
  # rdoc-file=numeric.c
1329
- # - self - numeric -> numeric_result
1321
+ # - self - other -> numeric
1330
1322
  # -->
1331
- # Performs subtraction:
1323
+ # Returns the difference of `self` and `other`:
1332
1324
  #
1333
1325
  # 4 - 2 # => 2
1334
1326
  # -4 - 2 # => -6
@@ -1368,7 +1360,7 @@ class Float
1368
1360
  # rdoc-file=numeric.c
1369
1361
  # - self / other -> numeric
1370
1362
  # -->
1371
- # Returns a new Float which is the result of dividing `self` by `other`:
1363
+ # Returns the quotient of `self` and `other`:
1372
1364
  #
1373
1365
  # f = 3.14
1374
1366
  # f / 2 # => 1.57
@@ -1383,7 +1375,7 @@ class Float
1383
1375
  # rdoc-file=numeric.c
1384
1376
  # - self * other -> numeric
1385
1377
  # -->
1386
- # Returns a new Float which is the product of `self` and `other`:
1378
+ # Returns the numeric product of `self` and `other`:
1387
1379
  #
1388
1380
  # f = 3.14
1389
1381
  # f * 2 # => 6.28
@@ -1396,15 +1388,20 @@ class Float
1396
1388
 
1397
1389
  # <!--
1398
1390
  # rdoc-file=numeric.c
1399
- # - self + other -> numeric
1391
+ # - self + other -> float or complex
1400
1392
  # -->
1401
- # Returns a new Float which is the sum of `self` and `other`:
1393
+ # Returns the sum of `self` and `other`; the result may be inexact (see Float):
1402
1394
  #
1403
- # f = 3.14
1404
- # f + 1 # => 4.140000000000001
1405
- # f + 1.0 # => 4.140000000000001
1406
- # f + Rational(1, 1) # => 4.140000000000001
1407
- # f + Complex(1, 0) # => (4.140000000000001+0i)
1395
+ # 3.14 + 0 # => 3.14
1396
+ # 3.14 + 1 # => 4.140000000000001
1397
+ # -3.14 + 0 # => -3.14
1398
+ # -3.14 + 1 # => -2.14
1399
+ #
1400
+ # 3.14 + -3.14 # => 0.0
1401
+ # -3.14 + -3.14 # => -6.28
1402
+ #
1403
+ # 3.14 + Complex(1, 0) # => (4.140000000000001+0i)
1404
+ # 3.14 + Rational(1, 1) # => 4.140000000000001
1408
1405
  #
1409
1406
  def +: (BigDecimal) -> BigDecimal
1410
1407
  | ...
@@ -1413,7 +1410,7 @@ class Float
1413
1410
  # rdoc-file=numeric.c
1414
1411
  # - self - other -> numeric
1415
1412
  # -->
1416
- # Returns a new Float which is the difference of `self` and `other`:
1413
+ # Returns the difference of `self` and `other`:
1417
1414
  #
1418
1415
  # f = 3.14
1419
1416
  # f - 1 # => 2.14
@@ -1468,10 +1465,9 @@ class Rational
1468
1465
 
1469
1466
  # <!--
1470
1467
  # rdoc-file=rational.c
1471
- # - rat / numeric -> numeric
1472
- # - rat.quo(numeric) -> numeric
1468
+ # - self / other -> numeric
1473
1469
  # -->
1474
- # Performs division.
1470
+ # Returns the quotient of `self` and `other`:
1475
1471
  #
1476
1472
  # Rational(2, 3) / Rational(2, 3) #=> (1/1)
1477
1473
  # Rational(900) / Rational(1) #=> (900/1)
@@ -1484,39 +1480,50 @@ class Rational
1484
1480
 
1485
1481
  # <!--
1486
1482
  # rdoc-file=rational.c
1487
- # - rat * numeric -> numeric
1483
+ # - self * other -> numeric
1488
1484
  # -->
1489
- # Performs multiplication.
1485
+ # Returns the numeric product of `self` and `other`:
1490
1486
  #
1491
- # Rational(2, 3) * Rational(2, 3) #=> (4/9)
1492
- # Rational(900) * Rational(1) #=> (900/1)
1493
- # Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
1494
- # Rational(9, 8) * 4 #=> (9/2)
1495
- # Rational(20, 9) * 9.8 #=> 21.77777777777778
1487
+ # Rational(9, 8) * 4 #=> (9/2)
1488
+ # Rational(20, 9) * 9.8 #=> 21.77777777777778
1489
+ # Rational(9, 8) * Complex(1, 2) # => ((9/8)+(9/4)*i)
1490
+ # Rational(2, 3) * Rational(2, 3) #=> (4/9)
1491
+ # Rational(900) * Rational(1) #=> (900/1)
1492
+ # Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
1496
1493
  #
1497
1494
  def *: (BigDecimal) -> BigDecimal
1498
1495
  | ...
1499
1496
 
1500
1497
  # <!--
1501
1498
  # rdoc-file=rational.c
1502
- # - rat + numeric -> numeric
1499
+ # - self + other -> numeric
1503
1500
  # -->
1504
- # Performs addition.
1501
+ # Returns the sum of `self` and `other`:
1502
+ #
1503
+ # Rational(2, 3) + 0 # => (2/3)
1504
+ # Rational(2, 3) + 1 # => (5/3)
1505
+ # Rational(2, 3) + -1 # => (-1/3)
1506
+ #
1507
+ # Rational(2, 3) + Complex(1, 0) # => ((5/3)+0i)
1505
1508
  #
1506
- # Rational(2, 3) + Rational(2, 3) #=> (4/3)
1507
- # Rational(900) + Rational(1) #=> (901/1)
1508
- # Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
1509
- # Rational(9, 8) + 4 #=> (41/8)
1510
- # Rational(20, 9) + 9.8 #=> 12.022222222222222
1509
+ # Rational(2, 3) + Rational(1, 1) # => (5/3)
1510
+ # Rational(2, 3) + Rational(3, 2) # => (13/6)
1511
+ # Rational(2, 3) + Rational(3.0, 2.0) # => (13/6)
1512
+ # Rational(2, 3) + Rational(3.1, 2.1) # => (30399297484750849/14186338826217063)
1513
+ #
1514
+ # For a computation involving Floats, the result may be inexact (see Float#+):
1515
+ #
1516
+ # Rational(2, 3) + 1.0 # => 1.6666666666666665
1517
+ # Rational(2, 3) + Complex(1.0, 0.0) # => (1.6666666666666665+0.0i)
1511
1518
  #
1512
1519
  def +: (BigDecimal) -> BigDecimal
1513
1520
  | ...
1514
1521
 
1515
1522
  # <!--
1516
1523
  # rdoc-file=rational.c
1517
- # - rat - numeric -> numeric
1524
+ # - self - other -> numeric
1518
1525
  # -->
1519
- # Performs subtraction.
1526
+ # Returns the difference of `self` and `other`:
1520
1527
  #
1521
1528
  # Rational(2, 3) - Rational(2, 3) #=> (0/1)
1522
1529
  # Rational(900) - Rational(1) #=> (899/1)
@@ -1553,9 +1560,9 @@ class Complex
1553
1560
 
1554
1561
  # <!--
1555
1562
  # rdoc-file=complex.c
1556
- # - complex / numeric -> new_complex
1563
+ # - self / other -> complex
1557
1564
  # -->
1558
- # Returns the quotient of `self` and `numeric`:
1565
+ # Returns the quotient of `self` and `other`:
1559
1566
  #
1560
1567
  # Complex.rect(2, 3) / Complex.rect(2, 3) # => (1+0i)
1561
1568
  # Complex.rect(900) / Complex.rect(1) # => (900+0i)
@@ -1568,39 +1575,50 @@ class Complex
1568
1575
 
1569
1576
  # <!--
1570
1577
  # rdoc-file=complex.c
1571
- # - complex * numeric -> new_complex
1578
+ # - self * other -> numeric
1572
1579
  # -->
1573
- # Returns the product of `self` and `numeric`:
1580
+ # Returns the numeric product of `self` and `other`:
1574
1581
  #
1582
+ # Complex.rect(9, 8) * 4 # => (36+32i)
1583
+ # Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
1575
1584
  # Complex.rect(2, 3) * Complex.rect(2, 3) # => (-5+12i)
1576
1585
  # Complex.rect(900) * Complex.rect(1) # => (900+0i)
1577
1586
  # Complex.rect(-2, 9) * Complex.rect(-9, 2) # => (0-85i)
1578
- # Complex.rect(9, 8) * 4 # => (36+32i)
1579
- # Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
1587
+ # Complex.rect(9, 8) * Rational(2, 3) # => ((6/1)+(16/3)*i)
1580
1588
  #
1581
1589
  def *: (BigDecimal) -> Complex
1582
1590
  | ...
1583
1591
 
1584
1592
  # <!--
1585
1593
  # rdoc-file=complex.c
1586
- # - complex + numeric -> new_complex
1594
+ # - self + other -> numeric
1587
1595
  # -->
1588
- # Returns the sum of `self` and `numeric`:
1596
+ # Returns the sum of `self` and `other`:
1597
+ #
1598
+ # Complex(1, 2) + 0 # => (1+2i)
1599
+ # Complex(1, 2) + 1 # => (2+2i)
1600
+ # Complex(1, 2) + -1 # => (0+2i)
1601
+ #
1602
+ # Complex(1, 2) + 1.0 # => (2.0+2i)
1603
+ #
1604
+ # Complex(1, 2) + Complex(2, 1) # => (3+3i)
1605
+ # Complex(1, 2) + Complex(2.0, 1.0) # => (3.0+3.0i)
1606
+ #
1607
+ # Complex(1, 2) + Rational(1, 1) # => ((2/1)+2i)
1608
+ # Complex(1, 2) + Rational(1, 2) # => ((3/2)+2i)
1609
+ #
1610
+ # For a computation involving Floats, the result may be inexact (see Float#+):
1589
1611
  #
1590
- # Complex.rect(2, 3) + Complex.rect(2, 3) # => (4+6i)
1591
- # Complex.rect(900) + Complex.rect(1) # => (901+0i)
1592
- # Complex.rect(-2, 9) + Complex.rect(-9, 2) # => (-11+11i)
1593
- # Complex.rect(9, 8) + 4 # => (13+8i)
1594
- # Complex.rect(20, 9) + 9.8 # => (29.8+9i)
1612
+ # Complex(1, 2) + 3.14 # => (4.140000000000001+2i)
1595
1613
  #
1596
1614
  def +: (BigDecimal) -> Complex
1597
1615
  | ...
1598
1616
 
1599
1617
  # <!--
1600
1618
  # rdoc-file=complex.c
1601
- # - complex - numeric -> new_complex
1619
+ # - self - other -> complex
1602
1620
  # -->
1603
- # Returns the difference of `self` and `numeric`:
1621
+ # Returns the difference of `self` and `other`:
1604
1622
  #
1605
1623
  # Complex.rect(2, 3) - Complex.rect(2, 3) # => (0+0i)
1606
1624
  # Complex.rect(900) - Complex.rect(1) # => (899+0i)