Skip to content

Instantly share code, notes, and snippets.

@skade
Forked from mmack/gist:4174856
Created November 30, 2012 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skade/4174945 to your computer and use it in GitHub Desktop.
Save skade/4174945 to your computer and use it in GitHub Desktop.
f = -> h,k { h[k] = Hash.new(&f) }
h = Hash.new &f
data = {
"80e33bc0-1b9a-0130-d2fb-38f6b113e413:data:message:name" => "max",
"80e33bc0-1b9a-0130-d2fb-38f6b113e413:data:text" => "bla",
"80e33bc0-1b9a-0130-d2fb-38f6b113e413:data:message:line:x" => 123
}
data.each do |path, v|
split_path = path.split(":")
top = split_path[0..-2].inject(h) do |h,p|
h[p]
end
top[split_path.last] = v
end
puts h.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment