rbs 2.0.0 → 2.2.2

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 (208) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +34 -0
  3. data/.github/workflows/ruby.yml +5 -0
  4. data/CHANGELOG.md +82 -0
  5. data/README.md +6 -1
  6. data/Rakefile +56 -21
  7. data/core/array.rbs +2866 -1086
  8. data/core/basic_object.rbs +150 -30
  9. data/core/binding.rbs +33 -0
  10. data/core/builtin.rbs +4 -4
  11. data/core/class.rbs +43 -5
  12. data/core/comparable.rbs +57 -0
  13. data/core/complex.rbs +170 -4
  14. data/core/constants.rbs +51 -0
  15. data/core/deprecated.rbs +7 -0
  16. data/core/dir.rbs +305 -20
  17. data/core/encoding.rbs +1214 -77
  18. data/core/enumerable.rbs +2173 -234
  19. data/core/enumerator.rbs +448 -182
  20. data/core/env.rbs +448 -1
  21. data/core/errno.rbs +1 -10
  22. data/core/errors.rbs +152 -2
  23. data/core/exception.rbs +201 -127
  24. data/core/false_class.rbs +27 -0
  25. data/core/fiber.rbs +118 -37
  26. data/core/fiber_error.rbs +8 -9
  27. data/core/file.rbs +1060 -142
  28. data/core/file_test.rbs +287 -32
  29. data/core/float.rbs +776 -300
  30. data/core/gc.rbs +185 -34
  31. data/core/global_variables.rbs +5 -1
  32. data/core/hash.rbs +1582 -649
  33. data/core/integer.rbs +974 -204
  34. data/core/io/buffer.rbs +710 -0
  35. data/core/io/wait.rbs +29 -8
  36. data/core/io.rbs +2438 -417
  37. data/core/kernel.rbs +2319 -318
  38. data/core/marshal.rbs +37 -2
  39. data/core/match_data.rbs +123 -6
  40. data/core/math.rbs +126 -6
  41. data/core/method.rbs +226 -102
  42. data/core/module.rbs +421 -45
  43. data/core/nil_class.rbs +64 -0
  44. data/core/numeric.rbs +620 -142
  45. data/core/object.rbs +453 -81
  46. data/core/object_space.rbs +92 -2
  47. data/core/proc.rbs +482 -285
  48. data/core/process.rbs +443 -34
  49. data/core/ractor.rbs +232 -9
  50. data/core/random.rbs +151 -52
  51. data/core/range.rbs +885 -160
  52. data/core/rational.rbs +122 -6
  53. data/core/rb_config.rbs +14 -4
  54. data/core/refinement.rbs +44 -0
  55. data/core/regexp.rbs +156 -14
  56. data/core/ruby_vm.rbs +42 -3
  57. data/core/signal.rbs +78 -39
  58. data/core/string.rbs +2123 -567
  59. data/core/string_io.rbs +204 -0
  60. data/core/struct.rbs +283 -28
  61. data/core/symbol.rbs +304 -30
  62. data/core/thread.rbs +1288 -688
  63. data/core/thread_group.rbs +66 -10
  64. data/core/time.rbs +643 -217
  65. data/core/trace_point.rbs +100 -12
  66. data/core/true_class.rbs +24 -0
  67. data/core/unbound_method.rbs +73 -7
  68. data/core/warning.rbs +37 -12
  69. data/docs/CONTRIBUTING.md +40 -34
  70. data/docs/stdlib.md +3 -102
  71. data/docs/syntax.md +54 -11
  72. data/ext/rbs_extension/extconf.rb +1 -0
  73. data/ext/rbs_extension/lexer.h +5 -0
  74. data/ext/rbs_extension/lexstate.c +6 -0
  75. data/ext/rbs_extension/parser.c +85 -10
  76. data/ext/rbs_extension/ruby_objs.c +4 -2
  77. data/ext/rbs_extension/ruby_objs.h +2 -2
  78. data/goodcheck.yml +0 -11
  79. data/lib/rbs/annotate/annotations.rb +197 -0
  80. data/lib/rbs/annotate/formatter.rb +80 -0
  81. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  82. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  83. data/lib/rbs/annotate.rb +6 -0
  84. data/lib/rbs/ast/members.rb +21 -13
  85. data/lib/rbs/buffer.rb +17 -11
  86. data/lib/rbs/cli.rb +48 -1
  87. data/lib/rbs/definition_builder/method_builder.rb +28 -16
  88. data/lib/rbs/definition_builder.rb +6 -2
  89. data/lib/rbs/environment.rb +8 -4
  90. data/lib/rbs/location_aux.rb +12 -0
  91. data/lib/rbs/namespace.rb +1 -1
  92. data/lib/rbs/prototype/rb.rb +12 -0
  93. data/lib/rbs/type_alias_regularity.rb +6 -4
  94. data/lib/rbs/type_name.rb +1 -1
  95. data/lib/rbs/types.rb +1 -1
  96. data/lib/rbs/validator.rb +6 -0
  97. data/lib/rbs/version.rb +1 -1
  98. data/lib/rbs/writer.rb +54 -4
  99. data/lib/rbs.rb +0 -2
  100. data/schema/typeParam.json +3 -3
  101. data/sig/annotate/annotations.rbs +102 -0
  102. data/sig/annotate/formatter.rbs +24 -0
  103. data/sig/annotate/rdoc_annotater.rbs +82 -0
  104. data/sig/annotate/rdoc_source.rbs +30 -0
  105. data/sig/buffer.rbs +6 -2
  106. data/sig/cli.rbs +2 -0
  107. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  108. data/sig/location.rbs +6 -0
  109. data/sig/members.rbs +24 -18
  110. data/sig/method_builder.rbs +5 -4
  111. data/sig/method_types.rbs +5 -1
  112. data/sig/polyfill.rbs +78 -0
  113. data/sig/validator.rbs +3 -1
  114. data/sig/writer.rbs +79 -2
  115. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  116. data/stdlib/abbrev/0/array.rbs +26 -0
  117. data/stdlib/base64/0/base64.rbs +31 -0
  118. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  119. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  120. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  121. data/stdlib/cgi/0/core.rbs +649 -21
  122. data/stdlib/coverage/0/coverage.rbs +164 -2
  123. data/stdlib/csv/0/csv.rbs +2862 -398
  124. data/stdlib/date/0/date.rbs +483 -25
  125. data/stdlib/date/0/date_time.rbs +187 -12
  126. data/stdlib/dbm/0/dbm.rbs +152 -17
  127. data/stdlib/digest/0/digest.rbs +146 -0
  128. data/stdlib/erb/0/erb.rbs +65 -245
  129. data/stdlib/fiber/0/fiber.rbs +73 -91
  130. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  131. data/stdlib/find/0/find.rbs +9 -0
  132. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  133. data/stdlib/io-console/0/io-console.rbs +227 -15
  134. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  135. data/stdlib/json/0/json.rbs +1147 -145
  136. data/stdlib/logger/0/formatter.rbs +24 -0
  137. data/stdlib/logger/0/log_device.rbs +64 -0
  138. data/stdlib/logger/0/logger.rbs +165 -13
  139. data/stdlib/logger/0/period.rbs +10 -0
  140. data/stdlib/logger/0/severity.rbs +26 -0
  141. data/stdlib/monitor/0/monitor.rbs +163 -0
  142. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  143. data/stdlib/net-http/0/manifest.yaml +1 -0
  144. data/stdlib/net-http/0/net-http.rbs +1513 -683
  145. data/stdlib/nkf/0/nkf.rbs +372 -0
  146. data/stdlib/objspace/0/objspace.rbs +149 -90
  147. data/stdlib/openssl/0/openssl.rbs +8108 -71
  148. data/stdlib/optparse/0/optparse.rbs +487 -19
  149. data/stdlib/pathname/0/pathname.rbs +425 -124
  150. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  151. data/stdlib/prime/0/integer-extension.rbs +20 -2
  152. data/stdlib/prime/0/prime.rbs +88 -21
  153. data/stdlib/pstore/0/pstore.rbs +102 -0
  154. data/stdlib/pty/0/pty.rbs +64 -14
  155. data/stdlib/resolv/0/resolv.rbs +420 -31
  156. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  157. data/stdlib/rubygems/0/config_file.rbs +33 -1
  158. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  159. data/stdlib/rubygems/0/installer.rbs +13 -1
  160. data/stdlib/rubygems/0/path_support.rbs +4 -1
  161. data/stdlib/rubygems/0/platform.rbs +5 -1
  162. data/stdlib/rubygems/0/request_set.rbs +44 -2
  163. data/stdlib/rubygems/0/requirement.rbs +65 -2
  164. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  165. data/stdlib/rubygems/0/source_list.rbs +13 -0
  166. data/stdlib/rubygems/0/specification.rbs +21 -1
  167. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  168. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  169. data/stdlib/rubygems/0/version.rbs +60 -157
  170. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  171. data/stdlib/set/0/set.rbs +423 -109
  172. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  173. data/stdlib/singleton/0/singleton.rbs +20 -0
  174. data/stdlib/socket/0/addrinfo.rbs +210 -9
  175. data/stdlib/socket/0/basic_socket.rbs +103 -11
  176. data/stdlib/socket/0/ip_socket.rbs +31 -9
  177. data/stdlib/socket/0/socket.rbs +586 -38
  178. data/stdlib/socket/0/tcp_server.rbs +22 -2
  179. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  180. data/stdlib/socket/0/udp_socket.rbs +25 -2
  181. data/stdlib/socket/0/unix_server.rbs +22 -2
  182. data/stdlib/socket/0/unix_socket.rbs +45 -5
  183. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  184. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  185. data/stdlib/time/0/time.rbs +208 -116
  186. data/stdlib/timeout/0/timeout.rbs +10 -0
  187. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  188. data/stdlib/tsort/0/cyclic.rbs +1 -0
  189. data/stdlib/tsort/0/interfaces.rbs +1 -0
  190. data/stdlib/tsort/0/tsort.rbs +42 -0
  191. data/stdlib/uri/0/common.rbs +57 -8
  192. data/stdlib/uri/0/file.rbs +55 -109
  193. data/stdlib/uri/0/ftp.rbs +6 -3
  194. data/stdlib/uri/0/generic.rbs +558 -329
  195. data/stdlib/uri/0/http.rbs +60 -114
  196. data/stdlib/uri/0/https.rbs +8 -102
  197. data/stdlib/uri/0/ldap.rbs +143 -137
  198. data/stdlib/uri/0/ldaps.rbs +8 -102
  199. data/stdlib/uri/0/mailto.rbs +3 -0
  200. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  201. data/stdlib/uri/0/ws.rbs +6 -3
  202. data/stdlib/uri/0/wss.rbs +5 -3
  203. data/stdlib/yaml/0/dbm.rbs +151 -87
  204. data/stdlib/yaml/0/store.rbs +6 -0
  205. data/stdlib/zlib/0/zlib.rbs +90 -31
  206. metadata +18 -6
  207. data/lib/rbs/location.rb +0 -221
  208. data/sig/char_scanner.rbs +0 -9
data/core/range.rbs CHANGED
@@ -1,226 +1,951 @@
1
- # A `Range` represents an interval—a set of values with a beginning and an
2
- # end. Ranges may be constructed using the *s* `..` *e* and *s* `...` *e*
3
- # literals, or with [::new](Range#method-c-new).
4
- # Ranges constructed using `..` run from the beginning to the end
5
- # inclusively. Those created using `...` exclude the end value. When used
6
- # as an iterator, ranges return each value in the sequence.
7
- #
8
- # ```ruby
9
- # (-1..-5).to_a #=> []
10
- # (-5..-1).to_a #=> [-5, -4, -3, -2, -1]
11
- # ('a'..'e').to_a #=> ["a", "b", "c", "d", "e"]
12
- # ('a'...'e').to_a #=> ["a", "b", "c", "d"]
13
- # ```
14
- #
15
- #
16
- # An “endless range” represents a semi-infinite range. Literal notation
17
- # for an endless range is:
18
- #
19
- # (1..)
20
- # # or similarly
21
- # (1...)
22
- #
23
- # Which is equivalent to
24
- #
25
- # ```ruby
26
- # (1..nil) # or similarly (1...nil)
27
- # Range.new(1, nil) # or Range.new(1, nil, true)
28
- # ```
29
- #
30
- # Endless ranges are useful, for example, for idiomatic slicing of arrays:
31
- #
32
- # [1, 2, 3, 4, 5][2...] # => [3, 4, 5]
33
- #
34
- # Some implementation details:
35
- #
36
- # - `end` of endless range is `nil` ;
37
- #
38
- # - `each` of endless range enumerates infinite sequence (may be useful
39
- # in combination with
40
- # [Enumerable\#take\_while](https://ruby-doc.org/core-2.6.3/Enumerable.html#method-i-take_while)
41
- # or similar methods);
42
- #
43
- # - `(1..)` and `(1...)` are not equal, although technically
44
- # representing the same sequence.
45
- #
46
- #
47
- # Ranges can be constructed using any objects that can be compared using
48
- # the `<=>` operator. Methods that treat the range as a sequence (\#each
49
- # and methods inherited from
50
- # [Enumerable](https://ruby-doc.org/core-2.6.3/Enumerable.html) ) expect
51
- # the begin object to implement a `succ` method to return the next object
52
- # in sequence. The [step](Range#method-i-step) and
53
- # [include?](Range#method-i-include-3F) methods
54
- # require the begin object to implement `succ` or to be numeric.
55
- #
56
- # In the `Xs` class below both `<=>` and `succ` are implemented so `Xs`
57
- # can be used to construct ranges. Note that the
58
- # [Comparable](https://ruby-doc.org/core-2.6.3/Comparable.html) module is
59
- # included so the `==` method is defined in terms of `<=>` .
60
- #
61
- # ```ruby
62
- # class Xs # represent a string of 'x's
63
- # include Comparable
64
- # attr :length
65
- # def initialize(n)
66
- # @length = n
67
- # end
68
- # def succ
69
- # Xs.new(@length + 1)
70
- # end
71
- # def <=>(other)
72
- # @length <=> other.length
73
- # end
74
- # def to_s
75
- # sprintf "%2d #{inspect}", @length
76
- # end
77
- # def inspect
78
- # 'x' * @length
79
- # end
80
- # end
81
- # ```
82
- #
83
- # An example of using `Xs` to construct a range:
84
- #
85
- # ```ruby
86
- # r = Xs.new(3)..Xs.new(6) #=> xxx..xxxxxx
87
- # r.to_a #=> [xxx, xxxx, xxxxx, xxxxxx]
88
- # r.member?(Xs.new(5)) #=> true
89
- # ```
1
+ # <!-- rdoc-file=range.c -->
2
+ # A Range object represents a collection of values that are between given begin
3
+ # and end values.
4
+ #
5
+ # You can create an Range object explicitly with:
6
+ #
7
+ # * A [range literal](doc/syntax/literals_rdoc.html#label-Range+Literals):
8
+ #
9
+ # # Ranges that use '..' to include the given end value.
10
+ # (1..4).to_a # => [1, 2, 3, 4]
11
+ # ('a'..'d').to_a # => ["a", "b", "c", "d"]
12
+ # # Ranges that use '...' to exclude the given end value.
13
+ # (1...4).to_a # => [1, 2, 3]
14
+ # ('a'...'d').to_a # => ["a", "b", "c"]
15
+ #
16
+ #
17
+ # A range may be created using method Range.new:
18
+ #
19
+ # # Ranges that by default include the given end value.
20
+ # Range.new(1, 4).to_a # => [1, 2, 3, 4]
21
+ # Range.new('a', 'd').to_a # => ["a", "b", "c", "d"]
22
+ # # Ranges that use third argument +exclude_end+ to exclude the given end value.
23
+ # Range.new(1, 4, true).to_a # => [1, 2, 3]
24
+ # Range.new('a', 'd', true).to_a # => ["a", "b", "c"]
25
+ #
26
+ # ## Beginless Ranges
27
+ #
28
+ # A *beginless* *range* has a definite end value, but a `nil` begin value. Such
29
+ # a range includes all values up to the end value.
30
+ #
31
+ # r = (..4) # => nil..4
32
+ # r.begin # => nil
33
+ # r.include?(-50) # => true
34
+ # r.include?(4) # => true
35
+ #
36
+ # r = (...4) # => nil...4
37
+ # r.include?(4) # => false
38
+ #
39
+ # Range.new(nil, 4) # => nil..4
40
+ # Range.new(nil, 4, true) # => nil...4
41
+ #
42
+ # A beginless range may be used to slice an array:
43
+ #
44
+ # a = [1, 2, 3, 4]
45
+ # r = (..2) # => nil...2
46
+ # a[r] # => [1, 2]
47
+ #
48
+ # Method `each` for a beginless range raises an exception.
49
+ #
50
+ # ## Endless Ranges
51
+ #
52
+ # An *endless* *range* has a definite begin value, but a `nil` end value. Such a
53
+ # range includes all values from the begin value.
54
+ #
55
+ # r = (1..) # => 1..
56
+ # r.end # => nil
57
+ # r.include?(50) # => true
58
+ #
59
+ # Range.new(1, nil) # => 1..
60
+ #
61
+ # The literal for an endless range may be written with either two dots or
62
+ # three. The range has the same elements, either way. But note that the two are
63
+ # not equal:
64
+ #
65
+ # r0 = (1..) # => 1..
66
+ # r1 = (1...) # => 1...
67
+ # r0.begin == r1.begin # => true
68
+ # r0.end == r1.end # => true
69
+ # r0 == r1 # => false
70
+ #
71
+ # An endless range may be used to slice an array:
72
+ #
73
+ # a = [1, 2, 3, 4]
74
+ # r = (2..) # => 2..
75
+ # a[r] # => [3, 4]
76
+ #
77
+ # Method `each` for an endless range calls the given block indefinitely:
78
+ #
79
+ # a = []
80
+ # r = (1..)
81
+ # r.each do |i|
82
+ # a.push(i) if i.even?
83
+ # break if i > 10
84
+ # end
85
+ # a # => [2, 4, 6, 8, 10]
86
+ #
87
+ # ## Ranges and Other Classes
88
+ #
89
+ # An object may be put into a range if its class implements instance method
90
+ # `<=>`. Ruby core classes that do so include Array, Complex, File::Stat, Float,
91
+ # Integer, Kernel, Module, Numeric, Rational, String, Symbol, and Time.
92
+ #
93
+ # Example:
94
+ #
95
+ # t0 = Time.now # => 2021-09-19 09:22:48.4854986 -0500
96
+ # t1 = Time.now # => 2021-09-19 09:22:56.0365079 -0500
97
+ # t2 = Time.now # => 2021-09-19 09:23:08.5263283 -0500
98
+ # (t0..t2).include?(t1) # => true
99
+ # (t0..t1).include?(t2) # => false
100
+ #
101
+ # A range can be iterated over only if its elements implement instance method
102
+ # `succ`. Ruby core classes that do so include Integer, String, and Symbol (but
103
+ # not the other classes mentioned above).
104
+ #
105
+ # Iterator methods include:
106
+ #
107
+ # * In Range itself: #each, #step, and #%
108
+ # * Included from module Enumerable: #each_entry, #each_with_index,
109
+ # #each_with_object, #each_slice, #each_cons, and #reverse_each.
110
+ #
111
+ #
112
+ # Example:
113
+ #
114
+ # a = []
115
+ # (1..4).each {|i| a.push(i) }
116
+ # a # => [1, 2, 3, 4]
117
+ #
118
+ # ## Ranges and User-Defined Classes
119
+ #
120
+ # A user-defined class that is to be used in a range must implement instance
121
+ # `<=>`; see [Integer#<=>](Integer.html#label-method-i-3C-3D-3E). To make
122
+ # iteration available, it must also implement instance method `succ`; see
123
+ # Integer#succ.
124
+ #
125
+ # The class below implements both `<=>` and `succ`, and so can be used both to
126
+ # construct ranges and to iterate over them. Note that the Comparable module is
127
+ # included so the `==` method is defined in terms of `<=>`.
128
+ #
129
+ # # Represent a string of 'X' characters.
130
+ # class Xs
131
+ # include Comparable
132
+ # attr_accessor :length
133
+ # def initialize(n)
134
+ # @length = n
135
+ # end
136
+ # def succ
137
+ # Xs.new(@length + 1)
138
+ # end
139
+ # def <=>(other)
140
+ # @length <=> other.length
141
+ # end
142
+ # def to_s
143
+ # sprintf "%2d #{inspect}", @length
144
+ # end
145
+ # def inspect
146
+ # 'X' * @length
147
+ # end
148
+ # end
149
+ #
150
+ # r = Xs.new(3)..Xs.new(6) #=> XXX..XXXXXX
151
+ # r.to_a #=> [XXX, XXXX, XXXXX, XXXXXX]
152
+ # r.include?(Xs.new(5)) #=> true
153
+ # r.include?(Xs.new(7)) #=> false
154
+ #
155
+ # ## What's Here
156
+ #
157
+ # First, what's elsewhere. Class Range:
158
+ #
159
+ # * Inherits from [class
160
+ # Object](Object.html#class-Object-label-What-27s+Here).
161
+ # * Includes [module
162
+ # Enumerable](Enumerable.html#module-Enumerable-label-What-27s+Here), which
163
+ # provides dozens of additional methods.
164
+ #
165
+ #
166
+ # Here, class Range provides methods that are useful for:
167
+ #
168
+ # * [Creating a Range](#class-Range-label-Methods+for+Creating+a+Range)
169
+ # * [Querying](#class-Range-label-Methods+for+Querying)
170
+ # * [Comparing](#class-Range-label-Methods+for+Comparing)
171
+ # * [Iterating](#class-Range-label-Methods+for+Iterating)
172
+ # * [Converting](#class-Range-label-Methods+for+Converting)
173
+ #
174
+ #
175
+ # ### Methods for Creating a Range
176
+ #
177
+ # ::new
178
+ # : Returns a new range.
179
+ #
180
+ #
181
+ #
182
+ # ### Methods for Querying
183
+ #
184
+ # #begin
185
+ # : Returns the begin value given for `self`.
186
+ #
187
+ # #bsearch
188
+ # : Returns an element from `self` selected by a binary search.
189
+ #
190
+ # #count
191
+ # : Returns a count of elements in `self`.
192
+ #
193
+ # #end
194
+ # : Returns the end value given for `self`.
195
+ #
196
+ # #exclude_end?
197
+ # : Returns whether the end object is excluded.
198
+ #
199
+ # #first
200
+ # : Returns the first elements of `self`.
201
+ #
202
+ # #hash
203
+ # : Returns the integer hash code.
204
+ #
205
+ # #last
206
+ # : Returns the last elements of `self`.
207
+ #
208
+ # #max
209
+ # : Returns the maximum values in `self`.
210
+ #
211
+ # #min
212
+ # : Returns the minimum values in `self`.
213
+ #
214
+ # #minmax
215
+ # : Returns the minimum and maximum values in `self`.
216
+ #
217
+ # #size
218
+ # : Returns the count of elements in `self`.
219
+ #
220
+ #
221
+ #
222
+ # ### Methods for Comparing
223
+ #
224
+ # [#==](#method-i-3D-3D)
225
+ # : Returns whether a given object is equal to `self` (uses #==).
226
+ #
227
+ # #===
228
+ # : Returns whether the given object is between the begin and end values.
229
+ #
230
+ # #cover?
231
+ # : Returns whether a given object is within `self`.
232
+ #
233
+ # #eql?
234
+ # : Returns whether a given object is equal to `self` (uses #eql?).
235
+ #
236
+ # #include? (aliased as #member?)
237
+ # : Returns whether a given object is an element of `self`.
238
+ #
239
+ #
240
+ #
241
+ # ### Methods for Iterating
242
+ #
243
+ # #%
244
+ # : Requires argument `n`; calls the block with each `n`-th element of
245
+ # `self`.
246
+ #
247
+ # #each
248
+ # : Calls the block with each element of `self`.
249
+ #
250
+ # #step
251
+ # : Takes optional argument `n` (defaults to 1); calls the block with each
252
+ # `n`-th element of `self`.
253
+ #
254
+ #
255
+ #
256
+ # ### Methods for Converting
257
+ #
258
+ # #inspect
259
+ # : Returns a string representation of `self` (uses #inspect).
260
+ #
261
+ # #to_a (aliased as #entries)
262
+ # : Returns elements of `self` in an array.
263
+ #
264
+ # #to_s
265
+ # : Returns a string representation of `self` (uses #to_s).
266
+ #
90
267
  class Range[out Elem] < Object
91
268
  include Enumerable[Elem]
92
269
 
270
+ # <!--
271
+ # rdoc-file=range.c
272
+ # - self == other -> true or false
273
+ # -->
274
+ # Returns `true` if and only if:
275
+ #
276
+ # * `other` is a range.
277
+ # * `other.begin == self.begin`.
278
+ # * `other.end == self.end`.
279
+ # * `other.exclude_end? == self.exclude_end?`.
280
+ #
281
+ #
282
+ # Otherwise returns `false`.
283
+ #
284
+ # r = (1..5)
285
+ # r == (1..5) # => true
286
+ # r = Range.new(1, 5)
287
+ # r == 'foo' # => false
288
+ # r == (2..5) # => false
289
+ # r == (1..4) # => false
290
+ # r == (1...5) # => false
291
+ # r == Range.new(1, 5, true) # => false
292
+ #
293
+ # Note that even with the same argument, the return values of #== and #eql? can
294
+ # differ:
295
+ #
296
+ # (1..2) == (1..2.0) # => true
297
+ # (1..2).eql? (1..2.0) # => false
298
+ #
299
+ # Related: Range#eql?.
300
+ #
93
301
  def ==: (untyped obj) -> bool
94
302
 
303
+ # <!--
304
+ # rdoc-file=range.c
305
+ # - self === object -> true or false
306
+ # -->
307
+ # Returns `true` if `object` is between `self.begin` and `self.end`. `false`
308
+ # otherwise:
309
+ #
310
+ # (1..4) === 2 # => true
311
+ # (1..4) === 5 # => false
312
+ # (1..4) === 'a' # => false
313
+ # (1..4) === 4 # => true
314
+ # (1...4) === 4 # => false
315
+ # ('a'..'d') === 'c' # => true
316
+ # ('a'..'d') === 'e' # => false
317
+ #
318
+ # A case statement uses method `===`, and so:
319
+ #
320
+ # case 79
321
+ # when (1..50)
322
+ # "low"
323
+ # when (51..75)
324
+ # "medium"
325
+ # when (76..100)
326
+ # "high"
327
+ # end # => "high"
328
+ #
329
+ # case "2.6.5"
330
+ # when ..."2.4"
331
+ # "EOL"
332
+ # when "2.4"..."2.5"
333
+ # "maintenance"
334
+ # when "2.5"..."3.0"
335
+ # "stable"
336
+ # when "3.1"..
337
+ # "upcoming"
338
+ # end # => "stable"
339
+ #
95
340
  def ===: (untyped obj) -> bool
96
341
 
97
- # Returns the object that defines the beginning of the range.
342
+ # <!--
343
+ # rdoc-file=range.c
344
+ # - self.begin -> object
345
+ # -->
346
+ # Returns the object that defines the beginning of `self`.
347
+ #
348
+ # (1..4).begin # => 1
349
+ # (..2).begin # => nil
98
350
  #
99
- # ```ruby
100
- # (1..10).begin #=> 1
101
- # ```
102
- def begin: () -> Elem # Begin-less ranges have type of Range[Integer?]
351
+ # Related: Range#first, Range#end.
352
+ #
353
+ def begin: () -> Elem
103
354
 
355
+ # <!--
356
+ # rdoc-file=range.c
357
+ # - bsearch {|obj| block } -> value
358
+ # -->
359
+ # Returns an element from `self` selected by a binary search.
360
+ #
361
+ # See [Binary Searching](rdoc-ref:bsearch.rdoc).
362
+ #
104
363
  def bsearch: () -> ::Enumerator[Elem, Elem?]
105
364
  | () { (Elem) -> (true | false) } -> Elem?
106
365
  | () { (Elem) -> ::Integer } -> Elem?
107
366
 
367
+ # <!--
368
+ # rdoc-file=range.c
369
+ # - cover?(object) -> true or false
370
+ # - cover?(range) -> true or false
371
+ # -->
372
+ # Returns `true` if the given argument is within `self`, `false` otherwise.
373
+ #
374
+ # With non-range argument `object`, evaluates with `<=` and `<`.
375
+ #
376
+ # For range `self` with included end value (`#exclude_end? == false`), evaluates
377
+ # thus:
378
+ #
379
+ # self.begin <= object <= self.end
380
+ #
381
+ # Examples:
382
+ #
383
+ # r = (1..4)
384
+ # r.cover?(1) # => true
385
+ # r.cover?(4) # => true
386
+ # r.cover?(0) # => false
387
+ # r.cover?(5) # => false
388
+ # r.cover?('foo') # => false
389
+ #
390
+ # r = ('a'..'d')
391
+ # r.cover?('a') # => true
392
+ # r.cover?('d') # => true
393
+ # r.cover?(' ') # => false
394
+ # r.cover?('e') # => false
395
+ # r.cover?(0) # => false
396
+ #
397
+ # For range `r` with excluded end value (`#exclude_end? == true`), evaluates
398
+ # thus:
399
+ #
400
+ # r.begin <= object < r.end
401
+ #
402
+ # Examples:
403
+ #
404
+ # r = (1...4)
405
+ # r.cover?(1) # => true
406
+ # r.cover?(3) # => true
407
+ # r.cover?(0) # => false
408
+ # r.cover?(4) # => false
409
+ # r.cover?('foo') # => false
410
+ #
411
+ # r = ('a'...'d')
412
+ # r.cover?('a') # => true
413
+ # r.cover?('c') # => true
414
+ # r.cover?(' ') # => false
415
+ # r.cover?('d') # => false
416
+ # r.cover?(0) # => false
417
+ #
418
+ # With range argument `range`, compares the first and last elements of `self`
419
+ # and `range`:
420
+ #
421
+ # r = (1..4)
422
+ # r.cover?(1..4) # => true
423
+ # r.cover?(0..4) # => false
424
+ # r.cover?(1..5) # => false
425
+ # r.cover?('a'..'d') # => false
426
+ #
427
+ # r = (1...4)
428
+ # r.cover?(1..3) # => true
429
+ # r.cover?(1..4) # => false
430
+ #
431
+ # If begin and end are numeric, #cover? behaves like #include?
432
+ #
433
+ # (1..3).cover?(1.5) # => true
434
+ # (1..3).include?(1.5) # => true
435
+ #
436
+ # But when not numeric, the two methods may differ:
437
+ #
438
+ # ('a'..'d').cover?('cc') # => true
439
+ # ('a'..'d').include?('cc') # => false
440
+ #
441
+ # Returns `false` if either:
442
+ #
443
+ # * The begin value of `self` is larger than its end value.
444
+ # * An internal call to `<=>` returns `nil`; that is, the operands are not
445
+ # comparable.
446
+ #
447
+ #
448
+ # Related: Range#include?.
449
+ #
108
450
  def cover?: (untyped obj) -> bool
109
451
 
452
+ # <!--
453
+ # rdoc-file=range.c
454
+ # - each {|element| ... } -> self
455
+ # - each -> an_enumerator
456
+ # -->
457
+ # With a block given, passes each element of `self` to the block:
458
+ #
459
+ # a = []
460
+ # (1..4).each {|element| a.push(element) } # => 1..4
461
+ # a # => [1, 2, 3, 4]
462
+ #
463
+ # Raises an exception unless `self.first.respond_to?(:succ)`.
464
+ #
465
+ # With no block given, returns an enumerator.
466
+ #
110
467
  def each: () { (Elem arg0) -> untyped } -> self
111
468
  | () -> ::Enumerator[Elem, self]
112
469
 
113
- # Returns the object that defines the end of the range.
470
+ # <!--
471
+ # rdoc-file=range.c
472
+ # - self.end -> object
473
+ # -->
474
+ # Returns the object that defines the end of `self`.
475
+ #
476
+ # (1..4).end # => 4
477
+ # (1...4).end # => 4
478
+ # (1..).end # => nil
479
+ #
480
+ # Related: Range#begin, Range#last.
114
481
  #
115
- # ```ruby
116
- # (1..10).end #=> 10
117
- # (1...10).end #=> 10
118
- # ```
119
- def `end`: () -> Elem # End-less ranges have type of Range[Integer?]
482
+ def end: () -> Elem
120
483
 
121
- # Returns `true` if the range excludes its end value.
484
+ # <!--
485
+ # rdoc-file=range.c
486
+ # - exclude_end? -> true or false
487
+ # -->
488
+ # Returns `true` if `self` excludes its end value; `false` otherwise:
122
489
  #
123
- # ```ruby
124
- # (1..5).exclude_end? #=> false
125
- # (1...5).exclude_end? #=> true
126
- # ```
127
- def `exclude_end?`: () -> bool
490
+ # Range.new(2, 5).exclude_end? # => false
491
+ # Range.new(2, 5, true).exclude_end? # => true
492
+ # (2..5).exclude_end? # => false
493
+ # (2...5).exclude_end? # => true
494
+ #
495
+ def exclude_end?: () -> bool
128
496
 
129
- # Returns the first object in the range, or an array of the first `n`
130
- # elements.
497
+ # <!--
498
+ # rdoc-file=range.c
499
+ # - first -> object
500
+ # - first(n) -> array
501
+ # -->
502
+ # With no argument, returns the first element of `self`, if it exists:
503
+ #
504
+ # (1..4).first # => 1
505
+ # ('a'..'d').first # => "a"
506
+ #
507
+ # With non-negative integer argument `n` given, returns the first `n` elements
508
+ # in an array:
509
+ #
510
+ # (1..10).first(3) # => [1, 2, 3]
511
+ # (1..10).first(0) # => []
512
+ # (1..4).first(50) # => [1, 2, 3, 4]
513
+ #
514
+ # Raises an exception if there is no first element:
515
+ #
516
+ # (..4).first # Raises RangeError
131
517
  #
132
- # ```ruby
133
- # (10..20).first #=> 10
134
- # (10..20).first(3) #=> [10, 11, 12]
135
- # ```
136
518
  def first: () -> Elem
137
519
  | (Integer n) -> ::Array[Elem]
138
520
 
139
- # Compute a hash-code for this range. Two ranges with equal begin and end
140
- # points (using `eql?` ), and the same
141
- # [exclude\_end?](Range.downloaded.ruby_doc#method-i-exclude_end-3F) value
142
- # will generate the same hash-code.
521
+ # <!--
522
+ # rdoc-file=range.c
523
+ # - hash -> integer
524
+ # -->
525
+ # Returns the integer hash value for `self`. Two range objects `r0` and `r1`
526
+ # have the same hash value if and only if `r0.eql?(r1)`.
527
+ #
528
+ # Related: Range#eql?, Object#hash.
143
529
  #
144
- # See also Object\#hash.
145
530
  def hash: () -> Integer
146
531
 
147
- def `include?`: (untyped obj) -> bool
532
+ # <!-- rdoc-file=range.c -->
533
+ # Returns `true` if `object` is an element of `self`, `false` otherwise:
534
+ #
535
+ # (1..4).include?(2) # => true
536
+ # (1..4).include?(5) # => false
537
+ # (1..4).include?(4) # => true
538
+ # (1...4).include?(4) # => false
539
+ # ('a'..'d').include?('b') # => true
540
+ # ('a'..'d').include?('e') # => false
541
+ # ('a'..'d').include?('B') # => false
542
+ # ('a'..'d').include?('d') # => true
543
+ # ('a'...'d').include?('d') # => false
544
+ #
545
+ # If begin and end are numeric, #include? behaves like #cover?
546
+ #
547
+ # (1..3).include?(1.5) # => true
548
+ # (1..3).cover?(1.5) # => true
549
+ #
550
+ # But when not numeric, the two methods may differ:
551
+ #
552
+ # ('a'..'d').include?('cc') # => false
553
+ # ('a'..'d').cover?('cc') # => true
554
+ #
555
+ # Related: Range#cover?.
556
+ #
557
+ # Range#member? is an alias for Range#include?.
558
+ #
559
+ def include?: (untyped obj) -> bool
148
560
 
561
+ # <!--
562
+ # rdoc-file=range.c
563
+ # - Range.new(begin, end, exclude_end = false) -> new_range
564
+ # -->
565
+ # Returns a new range based on the given objects `begin` and `end`. Optional
566
+ # argument `exclude_end` determines whether object `end` is included as the last
567
+ # object in the range:
568
+ #
569
+ # Range.new(2, 5).to_a # => [2, 3, 4, 5]
570
+ # Range.new(2, 5, true).to_a # => [2, 3, 4]
571
+ # Range.new('a', 'd').to_a # => ["a", "b", "c", "d"]
572
+ # Range.new('a', 'd', true).to_a # => ["a", "b", "c"]
573
+ #
149
574
  def initialize: (Elem from, Elem to, ?boolish exclude_end) -> void
150
575
 
151
- # Convert this range object to a printable form (using `inspect` to
152
- # convert the begin and end objects).
576
+ # <!--
577
+ # rdoc-file=range.c
578
+ # - inspect -> string
579
+ # -->
580
+ # Returns a string representation of `self`, including `begin.inspect` and
581
+ # `end.inspect`:
582
+ #
583
+ # (1..4).inspect # => "1..4"
584
+ # (1...4).inspect # => "1...4"
585
+ # (1..).inspect # => "1.."
586
+ # (..4).inspect # => "..4"
587
+ #
588
+ # Note that returns from #to_s and #inspect may differ:
589
+ #
590
+ # ('a'..'d').to_s # => "a..d"
591
+ # ('a'..'d').inspect # => "\"a\"..\"d\""
592
+ #
593
+ # Related: Range#to_s.
594
+ #
153
595
  def inspect: () -> String
154
596
 
155
- # Returns the last object in the range, or an array of the last `n`
156
- # elements.
597
+ # <!--
598
+ # rdoc-file=range.c
599
+ # - last -> object
600
+ # - last(n) -> array
601
+ # -->
602
+ # With no argument, returns the last element of `self`, if it exists:
603
+ #
604
+ # (1..4).last # => 4
605
+ # ('a'..'d').last # => "d"
157
606
  #
158
- # Note that with no arguments `last` will return the object that defines
159
- # the end of the range even if
160
- # [exclude\_end?](Range.downloaded.ruby_doc#method-i-exclude_end-3F) is
161
- # `true` .
607
+ # Note that `last` with no argument returns the end element of `self` even if
608
+ # #exclude_end? is `true`:
609
+ #
610
+ # (1...4).last # => 4
611
+ # ('a'...'d').last # => "d"
612
+ #
613
+ # With non-negative integer argument `n` given, returns the last `n` elements in
614
+ # an array:
615
+ #
616
+ # (1..10).last(3) # => [8, 9, 10]
617
+ # (1..10).last(0) # => []
618
+ # (1..4).last(50) # => [1, 2, 3, 4]
619
+ #
620
+ # Note that `last` with argument does not return the end element of `self` if
621
+ # #exclude_end? it `true`:
622
+ #
623
+ # (1...4).last(3) # => [1, 2, 3]
624
+ # ('a'...'d').last(3) # => ["a", "b", "c"]
625
+ #
626
+ # Raises an exception if there is no last element:
627
+ #
628
+ # (1..).last # Raises RangeError
162
629
  #
163
- # ```ruby
164
- # (10..20).last #=> 20
165
- # (10...20).last #=> 20
166
- # (10..20).last(3) #=> [18, 19, 20]
167
- # (10...20).last(3) #=> [17, 18, 19]
168
- # ```
169
630
  def last: () -> Elem
170
631
  | (Integer n) -> ::Array[Elem]
171
632
 
172
- # Returns the maximum value in the range. Returns `nil` if the begin value
173
- # of the range larger than the end value. Returns `nil` if the begin value
174
- # of an exclusive range is equal to the end value.
633
+ # <!--
634
+ # rdoc-file=range.c
635
+ # - max -> object
636
+ # - max(n) -> array
637
+ # - max {|a, b| ... } -> object
638
+ # - max(n) {|a, b| ... } -> array
639
+ # -->
640
+ # Returns the maximum value in `self`, using method `<=>` or a given block for
641
+ # comparison.
642
+ #
643
+ # With no argument and no block given, returns the maximum-valued element of
644
+ # `self`.
645
+ #
646
+ # (1..4).max # => 4
647
+ # ('a'..'d').max # => "d"
648
+ # (-4..-1).max # => -1
649
+ #
650
+ # With non-negative integer argument `n` given, and no block given, returns the
651
+ # `n` maximum-valued elements of `self` in an array:
652
+ #
653
+ # (1..4).max(2) # => [4, 3]
654
+ # ('a'..'d').max(2) # => ["d", "c"]
655
+ # (-4..-1).max(2) # => [-1, -2]
656
+ # (1..4).max(50) # => [4, 3, 2, 1]
657
+ #
658
+ # If a block is given, it is called:
659
+ #
660
+ # * First, with the first two element of `self`.
661
+ # * Then, sequentially, with the so-far maximum value and the next element of
662
+ # `self`.
663
+ #
664
+ #
665
+ # To illustrate:
666
+ #
667
+ # (1..4).max {|a, b| p [a, b]; a <=> b } # => 4
668
+ #
669
+ # Output:
670
+ #
671
+ # [2, 1]
672
+ # [3, 2]
673
+ # [4, 3]
674
+ #
675
+ # With no argument and a block given, returns the return value of the last call
676
+ # to the block:
677
+ #
678
+ # (1..4).max {|a, b| -(a <=> b) } # => 1
679
+ #
680
+ # With non-negative integer argument `n` given, and a block given, returns the
681
+ # return values of the last `n` calls to the block in an array:
682
+ #
683
+ # (1..4).max(2) {|a, b| -(a <=> b) } # => [1, 2]
684
+ # (1..4).max(50) {|a, b| -(a <=> b) } # => [1, 2, 3, 4]
685
+ #
686
+ # Returns an empty array if `n` is zero:
687
+ #
688
+ # (1..4).max(0) # => []
689
+ # (1..4).max(0) {|a, b| -(a <=> b) } # => []
690
+ #
691
+ # Returns `nil` or an empty array if:
692
+ #
693
+ # * The begin value of the range is larger than the end value:
694
+ #
695
+ # (4..1).max # => nil
696
+ # (4..1).max(2) # => []
697
+ # (4..1).max {|a, b| -(a <=> b) } # => nil
698
+ # (4..1).max(2) {|a, b| -(a <=> b) } # => []
699
+ #
700
+ # * The begin value of an exclusive range is equal to the end value:
701
+ #
702
+ # (1...1).max # => nil
703
+ # (1...1).max(2) # => []
704
+ # (1...1).max {|a, b| -(a <=> b) } # => nil
705
+ # (1...1).max(2) {|a, b| -(a <=> b) } # => []
706
+ #
175
707
  #
176
- # Can be given an optional block to override the default comparison method
177
- # `a <=> b` .
708
+ # Raises an exception if either:
709
+ #
710
+ # * `self` is a endless range: `(1..)`.
711
+ # * A block is given and `self` is a beginless range.
712
+ #
713
+ #
714
+ # Related: Range#min, Range#minmax.
178
715
  #
179
- # ```ruby
180
- # (10..20).max #=> 20
181
- # ```
182
716
  def max: () -> Elem
183
717
  | () { (Elem a, Elem b) -> Integer } -> Elem
184
718
  | (Integer n) -> ::Array[Elem]
185
719
  | (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
186
720
 
187
- # Returns the minimum value in the range. Returns `nil` if the begin value
188
- # of the range is larger than the end value. Returns `nil` if the begin
189
- # value of an exclusive range is equal to the end value.
721
+ # <!--
722
+ # rdoc-file=range.c
723
+ # - min -> object
724
+ # - min(n) -> array
725
+ # - min {|a, b| ... } -> object
726
+ # - min(n) {|a, b| ... } -> array
727
+ # -->
728
+ # Returns the minimum value in `self`, using method `<=>` or a given block for
729
+ # comparison.
730
+ #
731
+ # With no argument and no block given, returns the minimum-valued element of
732
+ # `self`.
733
+ #
734
+ # (1..4).min # => 1
735
+ # ('a'..'d').min # => "a"
736
+ # (-4..-1).min # => -4
737
+ #
738
+ # With non-negative integer argument `n` given, and no block given, returns the
739
+ # `n` minimum-valued elements of `self` in an array:
740
+ #
741
+ # (1..4).min(2) # => [1, 2]
742
+ # ('a'..'d').min(2) # => ["a", "b"]
743
+ # (-4..-1).min(2) # => [-4, -3]
744
+ # (1..4).min(50) # => [1, 2, 3, 4]
745
+ #
746
+ # If a block is given, it is called:
747
+ #
748
+ # * First, with the first two element of `self`.
749
+ # * Then, sequentially, with the so-far minimum value and the next element of
750
+ # `self`.
751
+ #
752
+ #
753
+ # To illustrate:
754
+ #
755
+ # (1..4).min {|a, b| p [a, b]; a <=> b } # => 1
756
+ #
757
+ # Output:
758
+ #
759
+ # [2, 1]
760
+ # [3, 1]
761
+ # [4, 1]
762
+ #
763
+ # With no argument and a block given, returns the return value of the last call
764
+ # to the block:
190
765
  #
191
- # Can be given an optional block to override the default comparison method
192
- # `a <=> b` .
766
+ # (1..4).min {|a, b| -(a <=> b) } # => 4
767
+ #
768
+ # With non-negative integer argument `n` given, and a block given, returns the
769
+ # return values of the last `n` calls to the block in an array:
770
+ #
771
+ # (1..4).min(2) {|a, b| -(a <=> b) } # => [4, 3]
772
+ # (1..4).min(50) {|a, b| -(a <=> b) } # => [4, 3, 2, 1]
773
+ #
774
+ # Returns an empty array if `n` is zero:
775
+ #
776
+ # (1..4).min(0) # => []
777
+ # (1..4).min(0) {|a, b| -(a <=> b) } # => []
778
+ #
779
+ # Returns `nil` or an empty array if:
780
+ #
781
+ # * The begin value of the range is larger than the end value:
782
+ #
783
+ # (4..1).min # => nil
784
+ # (4..1).min(2) # => []
785
+ # (4..1).min {|a, b| -(a <=> b) } # => nil
786
+ # (4..1).min(2) {|a, b| -(a <=> b) } # => []
787
+ #
788
+ # * The begin value of an exclusive range is equal to the end value:
789
+ #
790
+ # (1...1).min # => nil
791
+ # (1...1).min(2) # => []
792
+ # (1...1).min {|a, b| -(a <=> b) } # => nil
793
+ # (1...1).min(2) {|a, b| -(a <=> b) } # => []
794
+ #
795
+ #
796
+ # Raises an exception if either:
797
+ #
798
+ # * `self` is a beginless range: `(..4)`.
799
+ # * A block is given and `self` is an endless range.
800
+ #
801
+ #
802
+ # Related: Range#max, Range#minmax.
193
803
  #
194
- # ```ruby
195
- # (10..20).min #=> 10
196
- # ```
197
804
  def min: () -> Elem
198
805
  | () { (Elem a, Elem b) -> Integer } -> Elem
199
806
  | (Integer n) -> ::Array[Elem]
200
807
  | (Integer n) { (Elem a, Elem b) -> Integer } -> ::Array[Elem]
201
808
 
202
- # Returns the number of elements in the range. Both the begin and the end
203
- # of the [Range](Range.downloaded.ruby_doc) must be
204
- # [Numeric](https://ruby-doc.org/core-2.6.3/Numeric.html), otherwise nil
205
- # is returned.
809
+ # <!--
810
+ # rdoc-file=range.c
811
+ # - size -> non_negative_integer or Infinity or nil
812
+ # -->
813
+ # Returns the count of elements in `self` if both begin and end values are
814
+ # numeric; otherwise, returns `nil`:
815
+ #
816
+ # (1..4).size # => 4
817
+ # (1...4).size # => 3
818
+ # (1..).size # => Infinity
819
+ # ('a'..'z').size #=> nil
820
+ #
821
+ # Related: Range#count.
206
822
  #
207
- # ```ruby
208
- # (10..20).size #=> 11
209
- # ('a'..'z').size #=> nil
210
- # (-Float::INFINITY..Float::INFINITY).size #=> Infinity
211
- # ```
212
823
  def size: () -> Integer?
213
824
  | () -> Float?
214
825
 
826
+ # <!--
827
+ # rdoc-file=range.c
828
+ # - step(n = 1) {|element| ... } -> self
829
+ # - step(n = 1) -> enumerator
830
+ # -->
831
+ # Iterates over the elements of `self`.
832
+ #
833
+ # With a block given and no argument, calls the block each element of the range;
834
+ # returns `self`:
835
+ #
836
+ # a = []
837
+ # (1..5).step {|element| a.push(element) } # => 1..5
838
+ # a # => [1, 2, 3, 4, 5]
839
+ # a = []
840
+ # ('a'..'e').step {|element| a.push(element) } # => "a".."e"
841
+ # a # => ["a", "b", "c", "d", "e"]
842
+ #
843
+ # With a block given and a positive integer argument `n` given, calls the block
844
+ # with element `0`, element `n`, element `2n`, and so on:
845
+ #
846
+ # a = []
847
+ # (1..5).step(2) {|element| a.push(element) } # => 1..5
848
+ # a # => [1, 3, 5]
849
+ # a = []
850
+ # ('a'..'e').step(2) {|element| a.push(element) } # => "a".."e"
851
+ # a # => ["a", "c", "e"]
852
+ #
853
+ # With no block given, returns an enumerator, which will be of class
854
+ # Enumerator::ArithmeticSequence if `self` is numeric; otherwise of class
855
+ # Enumerator:
856
+ #
857
+ # e = (1..5).step(2) # => ((1..5).step(2))
858
+ # e.class # => Enumerator::ArithmeticSequence
859
+ # ('a'..'e').step # => #<Enumerator: ...>
860
+ #
861
+ # Related: Range#%.
862
+ #
215
863
  def step: (?Integer n) { (Elem arg0) -> untyped } -> self
216
864
  | (?Integer n) -> ::Enumerator[Elem, void]
217
865
 
218
- # Convert this range object to a printable form (using
219
- # [to\_s](Range.downloaded.ruby_doc#method-i-to_s) to convert the begin
220
- # and end objects).
866
+ # <!--
867
+ # rdoc-file=range.c
868
+ # - to_s -> string
869
+ # -->
870
+ # Returns a string representation of `self`, including `begin.to_s` and
871
+ # `end.to_s`:
872
+ #
873
+ # (1..4).to_s # => "1..4"
874
+ # (1...4).to_s # => "1...4"
875
+ # (1..).to_s # => "1.."
876
+ # (..4).to_s # => "..4"
877
+ #
878
+ # Note that returns from #to_s and #inspect may differ:
879
+ #
880
+ # ('a'..'d').to_s # => "a..d"
881
+ # ('a'..'d').inspect # => "\"a\"..\"d\""
882
+ #
883
+ # Related: Range#inspect.
884
+ #
221
885
  def to_s: () -> String
222
886
 
887
+ # <!--
888
+ # rdoc-file=range.c
889
+ # - eql?(other) -> true or false
890
+ # -->
891
+ # Returns `true` if and only if:
892
+ #
893
+ # * `other` is a range.
894
+ # * `other.begin eql? self.begin`.
895
+ # * `other.end eql? self.end`.
896
+ # * `other.exclude_end? == self.exclude_end?`.
897
+ #
898
+ #
899
+ # Otherwise returns `false`.
900
+ #
901
+ # r = (1..5)
902
+ # r.eql?(1..5) # => true
903
+ # r = Range.new(1, 5)
904
+ # r.eql?('foo') # => false
905
+ # r.eql?(2..5) # => false
906
+ # r.eql?(1..4) # => false
907
+ # r.eql?(1...5) # => false
908
+ # r.eql?(Range.new(1, 5, true)) # => false
909
+ #
910
+ # Note that even with the same argument, the return values of #== and #eql? can
911
+ # differ:
912
+ #
913
+ # (1..2) == (1..2.0) # => true
914
+ # (1..2).eql? (1..2.0) # => false
915
+ #
916
+ # Related: Range#==.
917
+ #
223
918
  def eql?: (untyped obj) -> bool
224
919
 
920
+ # <!--
921
+ # rdoc-file=range.c
922
+ # - include?(object) -> true or false
923
+ # -->
924
+ # Returns `true` if `object` is an element of `self`, `false` otherwise:
925
+ #
926
+ # (1..4).include?(2) # => true
927
+ # (1..4).include?(5) # => false
928
+ # (1..4).include?(4) # => true
929
+ # (1...4).include?(4) # => false
930
+ # ('a'..'d').include?('b') # => true
931
+ # ('a'..'d').include?('e') # => false
932
+ # ('a'..'d').include?('B') # => false
933
+ # ('a'..'d').include?('d') # => true
934
+ # ('a'...'d').include?('d') # => false
935
+ #
936
+ # If begin and end are numeric, #include? behaves like #cover?
937
+ #
938
+ # (1..3).include?(1.5) # => true
939
+ # (1..3).cover?(1.5) # => true
940
+ #
941
+ # But when not numeric, the two methods may differ:
942
+ #
943
+ # ('a'..'d').include?('cc') # => false
944
+ # ('a'..'d').cover?('cc') # => true
945
+ #
946
+ # Related: Range#cover?.
947
+ #
948
+ # Range#member? is an alias for Range#include?.
949
+ #
225
950
  def member?: (untyped obj) -> bool
226
951
  end