Last active
December 18, 2015 09:19
-
-
Save cupakromer/5760066 to your computer and use it in GitHub Desktop.
Magic Hashes All The Way Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
commented
Jun 11, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment