Skip to content

Commit

Permalink
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/array.cr
Original file line number Diff line number Diff line change
@@ -1454,7 +1454,7 @@ class Array(T)
end

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

# Removes the first value of `self`, at index 0. This method returns the removed value.
# If the array is empty, it returns `nil` without raising any error.
#
# ```
# a = ["a", "b"]
# a.shift? # => "a"
# a # => ["b"]
# a.shift? # => "b"
# a # => []
# a.shift? # => nil
# a # => []
# ```
def shift?
shift { nil }
end

0 comments on commit dca2887

Please sign in to comment.