[DOC] Tweaks for Array#first (#11687)

This commit is contained in:
Burdette Lamar 2024-09-29 20:21:55 -05:00 committed by GitHub
parent 116395d315
commit 5be11c1d1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -113,12 +113,12 @@ class Array
end end
# call-seq: # call-seq:
# array.first -> object or nil # first -> object or nil
# array.first(n) -> new_array # first(count) -> new_array
# #
# Returns elements from +self+; does not modify +self+. # Returns elements from +self+, or +nil+; does not modify +self+.
# #
# When no argument is given, returns the first element: # With no argument given, returns the first element (if available):
# #
# a = [:foo, 'bar', 2] # a = [:foo, 'bar', 2]
# a.first # => :foo # a.first # => :foo
@ -126,23 +126,16 @@ class Array
# #
# If +self+ is empty, returns +nil+. # If +self+ is empty, returns +nil+.
# #
# When non-negative Integer argument +n+ is given, # [].first # => nil
# returns the first +n+ elements in a new +Array+:
# #
# a = [:foo, 'bar', 2] # With non-negative integer argument +count+ given,
# a.first(2) # => [:foo, "bar"] # returns the first +count+ elements (as available) in a new array:
# #
# If <tt>n >= array.size</tt>, returns all elements: # a.first(0) # => []
# # a.first(2) # => [:foo, "bar"]
# a = [:foo, 'bar', 2]
# a.first(50) # => [:foo, "bar", 2] # a.first(50) # => [:foo, "bar", 2]
# #
# If <tt>n == 0</tt> returns an new empty +Array+: # Related: see {Methods for Querying}[rdoc-ref:Array@Methods+for+Querying].
#
# a = [:foo, 'bar', 2]
# a.first(0) # []
#
# Related: #last.
def first n = unspecified = true def first n = unspecified = true
if Primitive.mandatory_only? if Primitive.mandatory_only?
Primitive.attr! :leaf Primitive.attr! :leaf