check for nil array

Hi --

Hi --

Sam Woodard wrote:

unknown wrote:

Are you sure 0-8 are not empty arrays
rather than nil?

How would I check for that?

@months is an array of arrays. Month is that array containing Day
objects. Each Day object is nil in the month arrays in @month for
months 0-8 in the @months corresponding to 2006.

You could do:

   <% for month in @months %>
   <% next unless month[0] %> # test for non-nil value

or some similar test. Or, you could do this in your controller:

   @months.delete_if {|m| m[0].nil? }

or some other filtering operation, so that your @months array only
contains the sub-arrays you want.

David

if you say @month.compact! ruby removes any nil elements from the array. Its great for exactly this purpose.

dblack@wobblini.net wrote:

Nice, I was not aware of that.

Ivor wrote:

Hi --

Perhaps you could look at your code that generates and manipulates the
array and arrange for any unused element to always be nil. Or, you
could turn it into an object which has its own 'hascontent?'
flag/method?

Tonypm