Re: A more elegant way to do this?

Array() will do the job:

Array(nil) => []
Array([1,2,3]) => [1, 2, 3]
Array(1) => [1]

In your case:

Array(conf[‘hosts’][hostname][‘groups’]).each { … }

Gennady.