[DOC] Tweaks for Array#last (#11748)
This commit is contained in:
parent
2e2520ef10
commit
75ab01f3b7
Notes:
git
2024-10-02 14:55:36 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>
29
array.rb
29
array.rb
@ -150,36 +150,29 @@ class Array
|
|||||||
end
|
end
|
||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# array.last -> object or nil
|
# last -> last_object or nil
|
||||||
# array.last(n) -> new_array
|
# last(n) -> new_array
|
||||||
#
|
#
|
||||||
# Returns elements from +self+; +self+ is not modified.
|
# Returns elements from +self+, or +nil+; +self+ is not modified.
|
||||||
#
|
#
|
||||||
# When no argument is given, returns the last element:
|
# With no argument given, returns the last element, or +nil+ if +self+ is empty:
|
||||||
#
|
#
|
||||||
# a = [:foo, 'bar', 2]
|
# a = [:foo, 'bar', 2]
|
||||||
# a.last # => 2
|
# a.last # => 2
|
||||||
# a # => [:foo, "bar", 2]
|
# a # => [:foo, "bar", 2]
|
||||||
|
# [].last # => nil
|
||||||
#
|
#
|
||||||
# If +self+ is empty, returns +nil+.
|
|
||||||
#
|
#
|
||||||
# When non-negative Integer argument +n+ is given,
|
# With non-negative integer argument +n+ is given,
|
||||||
# returns the last +n+ elements in a new +Array+:
|
# returns a new array containing the trailing +n+ elements of +self+, as available:
|
||||||
#
|
|
||||||
# a = [:foo, 'bar', 2]
|
|
||||||
# a.last(2) # => ["bar", 2]
|
|
||||||
#
|
|
||||||
# If <tt>n >= array.size</tt>, returns all elements:
|
|
||||||
#
|
#
|
||||||
# a = [:foo, 'bar', 2]
|
# a = [:foo, 'bar', 2]
|
||||||
|
# a.last(2) # => ["bar", 2]
|
||||||
# a.last(50) # => [:foo, "bar", 2]
|
# a.last(50) # => [:foo, "bar", 2]
|
||||||
|
# a.last(0) # => []
|
||||||
|
# [].last(3) # => []
|
||||||
#
|
#
|
||||||
# If <tt>n == 0</tt>, returns an new empty +Array+:
|
# Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
|
||||||
#
|
|
||||||
# a = [:foo, 'bar', 2]
|
|
||||||
# a.last(0) # []
|
|
||||||
#
|
|
||||||
# Related: #first.
|
|
||||||
def last n = unspecified = true
|
def last n = unspecified = true
|
||||||
if Primitive.mandatory_only?
|
if Primitive.mandatory_only?
|
||||||
Primitive.attr! :leaf
|
Primitive.attr! :leaf
|
||||||
|
Loading…
x
Reference in New Issue
Block a user