On Thu, 11 May 2006, Tim Uckun wrote: > Can anybody suggest a more elegant and rubyish way to do this? > > I am reading a YAML file and then trying to iterate over arrays and > hashes that may or may not be there. > > unless conf['hosts'][hostname]['groups'].nil? > conf['hosts'][hostname]['groups'].each { |group| > unless conf['crontables'][group].nil? > conf['crontables'][group].each { | tab_item| > tab_entries << tab_item > } > end #Unless > } > end #unless > array = lambda{|x| x || []} array[conf['hosts'][hostname]['groups']].each {|group| array[conf['crontables'][group]].each {|tab_item| tab_entries << tab_item } } hth. -a -- be kind whenever possible... it is always possible. - h.h. the 14th dali lama