Skip to content

Instantly share code, notes, and snippets.

@ivopt
Created June 5, 2013 12:20
Show Gist options
  • Save ivopt/5713497 to your computer and use it in GitHub Desktop.
Save ivopt/5713497 to your computer and use it in GitHub Desktop.
A few augmentations to Ruby Hash..
class Hash
def self.infinite
self.new{|h, k| h[k] = self.new(&h.default_proc)}
end
def self.recursive max = nil
if max && max.kind_of?(Fixnum)
self.new{|h,k| h[k] = self.recursive(max-1) if max > 1}
else
infinite
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment