kernel/common/array.rb
# Returns the last element or n elements of self. If
# the Array is empty, without a count nil is returned,
# otherwise an empty Array. Always returns an Array.
Returns the last element or n elements of self. If
the Array is empty, without a count nil is returned,
otherwise an empty Array. Always returns an Array.
Returns the last element or n elements of self . If the Array is empty without a count nil is returned otherwise an empty Array . Always returns an Array .
def last(n = Undefined)
    if @total < 1
      return if n.equal? Undefined
      return []
    end
    return at(-1) if n.equal? Undefined
    unless n.respond_to?(:to_int)
      raise TypeError, "Can't convert #{n.class} into Integer"
    end
    n = Type.coerce_to n, Fixnum, :to_int
    return [] if n.zero?
    raise ArgumentError, "Number must be positive" if n < 0
    n = size if n > size
    Array.new self[-n..-1]
  end
def last ( n = Undefined ) if @total < 1 return if n . equal? Undefined return [ ] end return at ( - 1 ) if n . equal? Undefined unless n . respond_to? ( :to_int ) raise TypeError , "Can't convert #{n.class} into Integer" end n = Type . coerce_to n , Fixnum , :to_int return [ ] if n . zero? raise ArgumentError , "Number must be positive" if n < 0 n = size if n > size Array . new self [ - n .. - 1 ] end
Returns the last element or n elements of self.
Returns the last element or n elements of self .
n
<not_specific>