summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2022-04-25 13:07:35 -0700
committerJeremy Evans <code@jeremyevans.net>2022-04-25 13:07:35 -0700
commitf8724987db834c4672b44a55fddb779cec24422b (patch)
tree2b149cf1a8f9fafd09d0bb3ade7f4fb7028517f0 /range.c
parent9e8841e592c40e65bbad410a490c05f07a87052e (diff)
downloadruby-f8724987db834c4672b44a55fddb779cec24422b.tar.gz
Document beginless, endless ranges in Range class documentation
Diffstat (limited to 'range.c')
-rw-r--r--range.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/range.c b/range.c
index e0d27012b4..44c43047fd 100644
--- a/range.c
+++ b/range.c
@@ -2108,7 +2108,7 @@ range_count(int argc, VALUE *argv, VALUE range)
*
* Range.new(1, nil) # => 1..
*
- * The literal for an endless range may be written with either two dots
+ * The literal for an endless range may be written with either two dots
* or three.
* The range has the same elements, either way.
* But note that the two are not equal:
@@ -2135,6 +2135,15 @@ range_count(int argc, VALUE *argv, VALUE range)
* end
* a # => [2, 4, 6, 8, 10]
*
+ * A range can be both beginless and endless. For literal beginless, endless
+ * ranges, at least the beginning or end of the range must be given as an
+ * explicit nil value. It is recommended to use an explicit nil beginning and
+ * implicit nil end, since that is what Ruby uses for Range#inspect:
+ *
+ * (nil..) # => (nil..)
+ * (..nil) # => (nil..)
+ * (nil..nil) # => (nil..)
+ *
* == Ranges and Other Classes
*
* An object may be put into a range if its class implements