Skip to content

Commit dca2887

Browse files
porrasRX14
authored andcommittedSep 1, 2017
Document Array#shift? (#4886)
1 parent d1960a5 commit dca2887

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed
 

Diff for: ‎src/array.cr

+13-1
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ class Array(T)
14541454
end
14551455

14561456
# Removes the first value of `self`, at index 0. This method returns the removed value.
1457-
# Raises `IndexError` if array is of 0 size.
1457+
# If the array is empty, it raises `IndexError`.
14581458
#
14591459
# ```
14601460
# a = ["a", "b", "c"]
@@ -1507,6 +1507,18 @@ class Array(T)
15071507
ary
15081508
end
15091509

1510+
# Removes the first value of `self`, at index 0. This method returns the removed value.
1511+
# If the array is empty, it returns `nil` without raising any error.
1512+
#
1513+
# ```
1514+
# a = ["a", "b"]
1515+
# a.shift? # => "a"
1516+
# a # => ["b"]
1517+
# a.shift? # => "b"
1518+
# a # => []
1519+
# a.shift? # => nil
1520+
# a # => []
1521+
# ```
15101522
def shift?
15111523
shift { nil }
15121524
end

0 commit comments

Comments
 (0)
Please sign in to comment.