From: Christoffer Sawicki Date: 2006-05-12T22:45:06+09:00 Subject: Re: A more elegant way to do this? On 5/11/06, 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 > nil.to_a # => [] conf['hosts'][hostname]['groups'].to_a.each do |group| conf['crontables'][group].to_a.each do |tab_item| tab_entries << tab_item end end -- Christoffer Sawicki