instance method
Array#at
(::int index) -> Elem
at(index) → object or nil
array.c
View on GitHub ↗
VALUE
rb_ary_at(VALUE ary, VALUE pos)
{
return rb_ary_entry(ary, NUM2LONG(pos));
}
Returns the element of self specified by the given index or nil if there is no such element; index must be an integer-convertible object.
For non-negative index, returns the element of self at offset index:
Example
a = [:foo, 'bar', 2] a.at(0) # => :foo a.at(2) # => 2 a.at(2.0) # => 2
For negative index, counts backwards from the end of self:
Example
a.at(-2) # => "bar"
Related: Array#[]; see also Methods for Fetching.