File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -1454,7 +1454,7 @@ class Array(T)
1454
1454
end
1455
1455
1456
1456
# 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` .
1458
1458
#
1459
1459
# ```
1460
1460
# a = ["a", "b", "c"]
@@ -1507,6 +1507,18 @@ class Array(T)
1507
1507
ary
1508
1508
end
1509
1509
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
+ # ```
1510
1522
def shift ?
1511
1523
shift { nil }
1512
1524
end
You can’t perform that action at this time.
0 commit comments