Skip to content

Instantly share code, notes, and snippets.

@cupakromer
Last active December 18, 2015 09:19
Show Gist options
  • Save cupakromer/5760066 to your computer and use it in GitHub Desktop.
Save cupakromer/5760066 to your computer and use it in GitHub Desktop.
Magic Hashes All The Way Down
turtles_all_the_way_down = ->{ Hash.new{ |h, k| h[k] = turtles_all_the_way_down.call } }
magic_hash = Hash.new{ |h, k| h[k] = turtles_all_the_way_down.call }
magic_hash
# => {}
magic_hash['1']
# => {"1"=>{}}
magic_hash['1'] = 2
# => {"1"=>2}
magic_hash['2']['5'][:a] = 2
# => {"1"=>2, "2"=>{"5"=>{:a=>2}}}
@csexton
Copy link

csexton commented Jun 11, 2013

Thats some voodoo

@simplyb
Copy link

simplyb commented Jun 11, 2013

Magic

@csexton
Copy link

csexton commented Jun 11, 2013

mystical

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment