If an array happens to have one or more nil elements and these need to be removed, the Array#compact or Array#compact! methods can be used, as below.
array = [ 1, nil, 'hello', nil, '5', 33]
array.compact # => [ 1, 'hello', '5', 33]
#notice that the method returns a new copy of the array w...