Skip to content

Instantly share code, notes, and snippets.

@graywh
Created August 23, 2012 17:55
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 graywh/3439466 to your computer and use it in GitHub Desktop.
Save graywh/3439466 to your computer and use it in GitHub Desktop.
Auto-creating nested hashes via recursive proc
hash = lambda { |h, k| h[k] = Hash.new &hash }
x = Hash.new &hash
x[1][2][3][4][5] = 6
x #=> {1=>{2=>{3=>{4=>{5=>6}}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment