From: Robert Klemme Date: 2008-02-12T23:12:48+09:00 Subject: Re: nested hash from array of paths 2008/2/12, Phrogz : > On Feb 11, 10:00 pm, Phrogz wrote: > > array.each{ |path| > > sub = auto_hash > > path.split( "/" ).each{ |dir| sub[dir]; sub = sub[dir] } > > } > > Bah, of course that can be written as: > > array.each{ |path| > sub = auto_hash > path.split( "/" ).each{ |dir| sub = sub[dir] } > } Or even array.each{ |path| path.to_enum(:split, "/" ).inject(auto_hash){ |sub, dir| sub[dir] } } Full credits go to you for this line alone: auto_hash = Hash.new{ |h,k| h[k] = Hash.new &h.default_proc } Never occurred to me to use this nice one line approach instead of the usual two line version (first create block then use it). Thanks a lot, this is really a gem! Kind regards robert -- use.inject do |as, often| as.you_can - without end