rbs 3.10.0 → 4.0.0.dev.1

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