Skip to content

Commit f2f19cb

Browse files
committed
Add signature for Range#to_a
1 parent 352ad42 commit f2f19cb

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

core/range.rbs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,4 +1178,27 @@ class Range[out Elem] < Object
11781178
# Related: Range#cover?.
11791179
#
11801180
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
11811204
end

test/stdlib/Range_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,8 @@ def test_count
170170
assert_send_type "(::Integer) -> ::Integer", (1..4), :count, 2
171171
assert_send_type "() { (::Integer) -> boolish } -> ::Integer", (1..4), :count do |element| element < 3 end
172172
end
173+
174+
def test_to_a
175+
assert_send_type "() -> ::Array[::Integer]", (1..4), :to_a
176+
end
173177
end

0 commit comments

Comments
 (0)