From: "Jesús Gabriel y Galán" Date: 2012-04-13T16:35:59+09:00 Subject: Re: How to test if array element exists? On Fri, Apr 13, 2012 at 9:31 AM, Soul Surf wrote: > I'm new to Ruby and just want to test if an array element exists. Here's > a basic code snippet: > > array = [0,1,2,3] > > if [array[4]].empty? >  puts 'empty' > end > if [array[4]].nil? >  puts 'nil' > end if array[4].nil? What you are doing above is creating an array with one element, which is never nil: [nil].nil? > element 4 does not exist in the array, but neither of the if statements > result in true? what would be an if statement to check that array[4] > does not exist? Thanks Jesus.