@@ -825,6 +825,51 @@ class Range[out Elem] < Object
825825 #
826826 def min : ...
827827
828+ # <!--
829+ # rdoc-file=range.c
830+ # - minmax -> [object, object]
831+ # - minmax {|a, b| ... } -> [object, object]
832+ # -->
833+ # Returns a 2-element array containing the minimum and maximum value in `self`,
834+ # either according to comparison method `#<=>` or a given block.
835+ #
836+ # With no block given, returns the minimum and maximum values, using `#<=>` for
837+ # comparison:
838+ #
839+ # (1..4).minmax # => [1, 4]
840+ # (1...4).minmax # => [1, 3]
841+ # ('a'..'d').minmax # => ["a", "d"]
842+ # (-4..-1).minmax # => [-4, -1]
843+ #
844+ # With a block given, the block must return an integer:
845+ #
846+ # * Negative if `a` is smaller than `b`.
847+ # * Zero if `a` and `b` are equal.
848+ # * Positive if `a` is larger than `b`.
849+ #
850+ # The block is called `self.size` times to compare elements; returns a 2-element
851+ # Array containing the minimum and maximum values from `self`, per the block:
852+ #
853+ # (1..4).minmax {|a, b| -(a <=> b) } # => [4, 1]
854+ #
855+ # Returns `[nil, nil]` if:
856+ #
857+ # * The begin value of the range is larger than the end value:
858+ #
859+ # (4..1).minmax # => [nil, nil]
860+ # (4..1).minmax {|a, b| -(a <=> b) } # => [nil, nil]
861+ #
862+ # * The begin value of an exclusive range is equal to the end value:
863+ #
864+ # (1...1).minmax # => [nil, nil]
865+ # (1...1).minmax {|a, b| -(a <=> b) } # => [nil, nil]
866+ #
867+ # Raises an exception if `self` is a beginless or an endless range.
868+ #
869+ # Related: Range#min, Range#max.
870+ #
871+ def minmax : ...
872+
828873 # <!--
829874 # rdoc-file=range.c
830875 # - overlap?(range) -> true or false
@@ -932,6 +977,42 @@ class Range[out Elem] < Object
932977 #
933978 def size : () -> (Integer | Float | nil )
934979
980+ # <!--
981+ # rdoc-file=range.c
982+ # - count -> integer
983+ # - count(object) -> integer
984+ # - count {|element| ... } -> integer
985+ # -->
986+ # Returns the count of elements, based on an argument or block criterion, if
987+ # given.
988+ #
989+ # With no argument and no block given, returns the number of elements:
990+ #
991+ # (1..4).count # => 4
992+ # (1...4).count # => 3
993+ # ('a'..'d').count # => 4
994+ # ('a'...'d').count # => 3
995+ # (1..).count # => Infinity
996+ # (..4).count # => Infinity
997+ #
998+ # With argument `object`, returns the number of `object` found in `self`, which
999+ # will usually be zero or one:
1000+ #
1001+ # (1..4).count(2) # => 1
1002+ # (1..4).count(5) # => 0
1003+ # (1..4).count('a') # => 0
1004+ #
1005+ # With a block given, calls the block with each element; returns the number of
1006+ # elements for which the block returns a truthy value:
1007+ #
1008+ # (1..4).count {|element| element < 3 } # => 2
1009+ #
1010+ # Related: Range#size.
1011+ #
1012+ def count : () -> (Integer | Float)
1013+ | (untyped ) -> Integer
1014+ | () { (Elem) -> boolish } -> Integer
1015+
9351016 # <!--
9361017 # rdoc-file=range.c
9371018 # - step(s = 1) {|element| ... } -> self
@@ -1097,4 +1178,27 @@ class Range[out Elem] < Object
10971178 # Related: Range#cover?.
10981179 #
10991180 def member? : (untyped obj) -> bool
1181+
1182+ # <!--
1183+ # rdoc-file=range.c
1184+ # - to_a -> array
1185+ # -->
1186+ # Returns an array containing the elements in `self`, if a finite collection;
1187+ # raises an exception otherwise.
1188+ #
1189+ # (1..4).to_a # => [1, 2, 3, 4]
1190+ # (1...4).to_a # => [1, 2, 3]
1191+ # ('a'..'d').to_a # => ["a", "b", "c", "d"]
1192+ #
1193+ def to_a : ...
1194+
1195+ # <!-- rdoc-file=range.c -->
1196+ # Returns an array containing the elements in `self`, if a finite collection;
1197+ # raises an exception otherwise.
1198+ #
1199+ # (1..4).to_a # => [1, 2, 3, 4]
1200+ # (1...4).to_a # => [1, 2, 3]
1201+ # ('a'..'d').to_a # => ["a", "b", "c", "d"]
1202+ #
1203+ alias entries to_a
11001204end
0 commit comments