From: Ralf Mueller Date: 2012-04-13T17:00:06+09:00 Subject: Re: How to test if array element exists? On 04/13/2012 09:53 AM, Jan E. wrote: > Hi, > > If you access a non-existing index, you get nil. That is, your > expression [array[4]] evaluates to [nil], which is not empty (but has > exactly one element). > > The only way to test for existence is to check the length of the array: > > if 4>= array.length > puts 'no index 4' > end > what about this ?> array = [0,1,2,3] => [0, 1, 2, 3] >> array[4] => nil >> array[4].nil? => true >> array[444].nil? => true >> array[2].nil? => false >>