Method: Array#delete_at
- Defined in:
- array.c
#delete_at(index) ⇒ nil
Removes the element of self
at the given index
, which must be an integer-convertible object.
When index
is non-negative, deletes the element at offset index
:
a = [:foo, 'bar', 2]
a.delete_at(1) # => "bar"
a # => [:foo, 2]
When index
is negative, counts backward from the end of the array:
a = [:foo, 'bar', 2]
a.delete_at(-2) # => "bar"
a # => [:foo, 2]
When index
is out of range, returns nil
.
a = [:foo, 'bar', 2]
a.delete_at(3) # => nil
a.delete_at(-4) # => nil
Related: see Methods for Deleting.
4151 4152 4153 4154 4155 |
# File 'array.c', line 4151
static VALUE
rb_ary_delete_at_m(VALUE ary, VALUE pos)
{
return rb_ary_delete_at(ary, NUM2LONG(pos));
}
|