Skip to content

Instantly share code, notes, and snippets.

@maxjustus
Created June 25, 2012 18:49
Show Gist options
  • Save maxjustus/2990492 to your computer and use it in GitHub Desktop.
Save maxjustus/2990492 to your computer and use it in GitHub Desktop.
Infinitely nested hash (for caching and such)
module InfiniteHash
def self.new
Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
end
end
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