Created
June 25, 2012 18:49
-
-
Save maxjustus/2990492 to your computer and use it in GitHub Desktop.
Infinitely nested hash (for caching and such)
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
module InfiniteHash | |
def self.new | |
Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) } | |
end | |
end |
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
cache = InfiniteHash.new | |
cache[:herp][:derp] = 'Herp Derpelganger' | |
cache | |
=> {:herp => {:derp => 'Herp Derpelganger'}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment