From: Brian Katzung Date: 2013-07-31T02:58:40+09:00 Subject: Re: nested hash from array of paths Alternatively: require 'xkeys' array = ["home", "about", "about/history", "about/company", "about/history/part1", "about/history/part2"] tree = {}.extend XKeys::Hash array.each { |path| tree[*(path.split ?/)] = nil } p tree # {"home"=>nil, "about"=>{"history"=>{"part1"=>nil, "part2"=>nil}, # "company"=>nil}} The leaves are nil (not empty hashes), and the code is slightly less convoluted. -- Posted via http://www.ruby-forum.com/.