Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Array#shift? #4886

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/array.cr
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down