# (newbie) Array \> Element Assignment \> nil \> Documentation

**URL:** <https://www.ruby-forum.com/t/newbie-array-element-assignment-nil-documentation/189875>\
**Category:** Ruby\
**Created:** [June 9, 2010, 10:39am UTC](https://www.ruby-forum.com/t/newbie-array-element-assignment-nil-documentation/189875 "2010-06-09T10:39:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![potatopeelings](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@potatopeelings](https://www.ruby-forum.com/u/potatopeelings)\
**Post date:** [June 9, 2010, 10:39am UTC](https://www.ruby-forum.com/t/newbie-array-element-assignment-nil-documentation/189875/1 "2010-06-09T10:39:03Z")

</div>

Ruby version : 1.9.1.376  
OS : Windows

I’m checking [class Array - RDoc Documentation](http://ruby-doc.org/core/classes/Array.html#M002161) (Array  
element assignment) which says  
…If nil is used in the second and third form, _deletes_ elements  
from self…  
with the example  
a[1…-1] = nil #=\> [“A”]

This doesn’t seem to agree with how Ruby works now. puts a.to\_s gives me  
[“A”, nil]  
nil seems to work the way any other assignment would. The splice is just  
replaced with the new element.

Am I reading this wrong?

---

<div class="post-metadata">

**Author:** ![potatopeelings](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@potatopeelings](https://www.ruby-forum.com/u/potatopeelings)\
**Post date:** [June 9, 2010, 12:31pm UTC](https://www.ruby-forum.com/t/newbie-array-element-assignment-nil-documentation/189875/2 "2010-06-09T12:31:20Z")

</div>

On Wed, Jun 9, 2010 at 4:39 PM, Potato Peelings  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m checking [class Array - RDoc Documentation](http://ruby-doc.org/core/classes/Array.html#M002161) (Array

that’s an old and buggy doc

try this 1.9 doc

[class Array - RDoc Documentation](http://ruby-doc.org/core-1.9/classes/Array.html#M000418)

btw, you can also use ri

eg

$ ri Array#[]=  
Array#[]=

## (from ruby core)

ary[index] = obj → obj  
ary[start, length] = obj or other\_ary or nil → obj or other\_ary or  
nil  
ary[range] = obj or other\_ary or nil → obj or other\_ary or  
nil

* * *

Element Assignment—Sets the element at index, or replaces a subarray  
starting at start and continuing for length elements, or  
replaces a subarray specified by range. If indices are greater than  
the current capacity of the array, the array grows automatically. A  
negative  
indices will count backward from the end of the array. Inserts elements  
if  
length is zero. An IndexError is raised if a negative index  
points past the beginning of the array. See also Array#push, and  
Array#unshift.

a = Array.new  
a[4] = “4”; #=\> [nil, nil, nil, nil, “4”]  
a[0, 3] = [‘a’, ‘b’, ‘c’] #=\> [“a”, “b”, “c”, nil, “4”]  
a[1…2] = [1, 2] #=\> [“a”, 1, 2, nil, “4”]  
a[0, 2] = “?” #=\> [“?”, 2, nil, “4”]  
a[0…2] = “A” #=\> [“A”, “4”]  
a[-1] = “Z” #=\> [“A”, “Z”]  
a[1…-1] = nil #=\> [“A”, nil]  
a[1…-1] = [] #=\> [“A”]

best regards  
-botp

---

<div class="post-metadata">

**Author:** ![potatopeelings](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@potatopeelings](https://www.ruby-forum.com/u/potatopeelings)\
**Post date:** [June 10, 2010, 6:10am UTC](https://www.ruby-forum.com/t/newbie-array-element-assignment-nil-documentation/189875/3 "2010-06-10T06:10:57Z")

</div>

botp wrote:

> that’s an old and buggy doc
> 
> try this 1.9 doc  
> [class Array - RDoc Documentation](http://ruby-doc.org/core-1.9/classes/Array.html#M000418)

Thanks! That resolves it.

> btw, you can also use ri  
> This is nice. Thanks again.
