From: ara.t.howard@... Date: 2007-01-22T10:31:10+09:00 Subject: Re: Tricky: converting path into a Hash On Mon, 22 Jan 2007, Robert MannI wrote: > Hello! > > > I am wondering if the mighty ruby crowd has a brilliant idea for a tricky > problem I am solving. > > I need to store a path as a tree in a hash. > > Given: > a/b/c > > I want the Hash: > { 'a' => { 'b' => { 'c' => { } } } } > or written differently > hsh['a']['b']['c'] = {} > > Is there an elegant solution to this, without maybe looping or eval'ing too > much? > harp:~ > cat a.rb require 'pathname' class Pathname def to_hash ret = h = {} each_filename{|part| h[part] = (h={})} ret end end pn = Pathname.new 'a/b/c' p pn.to_hash harp:~ > ruby a.rb {"a"=>{"b"=>{"c"=>{}}}} -a -- we can deny everything, except that we have the possibility of being better. simply reflect on that. - the dalai lama