From: "Jan E." Date: 2012-04-13T17:04:51+09:00 Subject: Re: How to test if array element exists? Ralf Mueller wrote in post #1056271: > On 04/13/2012 09:53 AM, Jan E. wrote: >> 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 > >> This doesn't work, because nil may also be an actual element: array = [nil] puts array[0].nil? # true puts array[1].nil? # true So you cannot reliably tell if a certain element has been set (apart from the length solution mentioned above). -- Posted via http://www.ruby-forum.com/.