public Method

Array.at(p1)

array.at(index)      obj  or nil

Returns the element at index. A negative index counts from the end of self. Returns nil if the index is out of range. See also Array#[]. (Array#at is slightly faster than Array#[], as it does not accept ranges and so on.)

a = [ "a", "b", "c", "d", "e" ]
a.at(0)     #=> "a"
a.at(-1)    #=> "e"

Source Code

/* 
*  call-seq:
*     array.at(index)   ->   obj  or nil
*
*  Returns the element at _index_. A
*  negative index counts from the end of _self_.  Returns +nil+
*  if the index is out of range. See also <code>Array#[]</code>.
*  (<code>Array#at</code> is slightly faster than <code>Array#[]</code>,
*  as it does not accept ranges and so on.)
*
*     a = [ "a", "b", "c", "d", "e" ]
*     a.at(0)     #=> "a"
*     a.at(-1)    #=> "e"
*/

static VALUE
rb_ary_at(ary, pos)
   VALUE ary, pos;
{
   return rb_ary_entry(ary, NUM2LONG(pos));
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.