kernel/common/array.rb
# Attempts to return the element at the given index. By default
# an IndexError is raised if the element is out of bounds. The
# user may supply either a default value or a block that takes
# the index object instead.
Attempts to return the element at the given index. By default
an IndexError is raised if the element is out of bounds. The
user may supply either a default value or a block that takes
the index object instead.
Attempts to return the element at the given index . By default an IndexError is raised if the element is out of bounds . The user may supply either a default value or a block that takes the index object instead .
def fetch(idx, *rest)
    raise ArgumentError, "Expected 1-2, got #{1 + rest.length}" if rest.length > 1
    warn 'Block supercedes default object' if !rest.empty? && block_given?
    idx, orig = Type.coerce_to(idx, Fixnum, :to_int), idx
    idx += @total if idx < 0
    if idx < 0 || idx >= @total
      return yield(orig) if block_given?
      return rest.at(0) unless rest.empty?
      raise IndexError, "Index #{idx} out of array" if rest.empty?
    end
    at(idx)
  end
def fetch ( idx , * rest ) raise ArgumentError , "Expected 1-2, got #{1 + rest.length}" if rest . length > 1 warn 'Block supercedes default object' if ! rest . empty? && block_given? idx , orig = Type . coerce_to ( idx , Fixnum , :to_int ) , idx idx += @total if idx < 0 if idx < 0 || idx >= @total return yield ( orig ) if block_given? return rest . at ( 0 ) unless rest . empty? raise IndexError , "Index #{idx} out of array" if rest . empty? end at ( idx ) end
Attempts to return the element at the given index.
Attempts to return the element at the given index .
idx
<not_specific>
rest
<not_specific>