From: Love U Ruby Date: 2013-02-24T18:45:28+09:00 Subject: Confusion with `nil` value being produced by IRB in case of Array#size manipulation. enum[int] = obj → obj enum[start, length] = obj → obj enum[range] = obj → obj During my reading and understandding with the above I tried something in my IRB as below: a = [] # => [] a.size # => 0 Humm, understood. As no element I still added. a[0] # => nil a[1] # => nil as the array size is `0`, while trying to access the a[1] getting no exception - why so? that means index is there or what? what logic does help IRB to show such `nil` values? a[1] = 5 # => 5 a # => [nil, 5] The above code what should I say - new value addition or substitution of 'nil'? a.size # => 2 Okay! so now the size is `2`. Now in the below as the size is `2` thus a[3] is showing `nil`. a[3] <~~~~ point - I # => nil a.size # => 2 Now I added `nil` in the same index intentionaly. And the size got changed to `3`. a[3] = nil # => nil a.size # => 3 a[3] <~~~~ point - II # => nil What is the difference between the output of a[3] in point- I and point -II ? Why does both `nil` value being treated differently as mentioned above? -- Posted via http://www.ruby-forum.com/.